is:Conversion to logical form function_handle is not possible.

Hi I want to do a comparison with function handle. For example : Fun2=@(x) (4*x+1) While @(x)Fun2(x) >3 do something
The error is:Conversion to logical form function_handle is not possible. Thank a lot

 Respuesta aceptada

while Fun2(x) > 3
and be sure to update x inside the loop

2 comentarios

Thanks it worked.but now another error occurs: undefined function or variable 'a'. The code is attached
The message is correct. You do not define a or b before you try to use them in
while fun2(e,a,b)>10^(-6)||fun2(e,a,b)<-10^(-6)
Reminder: when you use
fun1=@(a,b)(b-a)./2;
then that does not define variables a or b: it defines only fun1 and it defines fun1 as being an anonymous function that accepts two positional parameters that for convenience are referred to as a and b.
fun1=@(a,b)(b-a)./2;
is coded sort of like
struct( 'formula', #(_Parameter{2}-_Parameter{1})./2)# , 'ParameterNames', {'a', 'b'})
in the sense that the execution of the code depends only on parameter position and the names of the parameters are (nearly) only used for display purposes.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 10 de Mayo de 2020

Editada:

el 10 de Mayo de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by