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

 採用された回答

Walter Roberson
Walter Roberson 2020 年 5 月 10 日

0 投票

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

2 件のコメント

Tara Behmanesh
Tara Behmanesh 2020 年 5 月 10 日
Thanks it worked.but now another error occurs: undefined function or variable 'a'. The code is attached
Walter Roberson
Walter Roberson 2020 年 5 月 10 日
編集済み: Walter Roberson 2020 年 5 月 10 日
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 ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by