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

 采纳的回答

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

2 个评论

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.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by