I think the code can run properly but at last there is an error "error: value on right hand side of assignment is undefined error called from :/Users/Apple/Downloads/HW1/Ex.m at line 2, column 3" appeared Here is my code:
function Bisection (a,b,f,DesireAccu)
Accu = 1;
while (Accu>DesireAccu)
c = (a+b)/2
Res = f(c)
Accu = abs(Res)
if (Accu < DesireAccu)
break;
else
Compare = f(a)*f(c);
if (Compare>0)
a = c;
else
b = c;
endif
endif
end
endfunction
f function is
function [retval] = OriFunc1 (X)
retval = sin(X)- X^3;
endfunction
And I use function handle to execute it:
g = @OriFunc1;
f = @Bisection(0,1,g,0.01)
Here is the result:

回答 (1 件)

Torsten
Torsten 2018 年 1 月 24 日

0 投票

To call a function or a script, just write its name:
Bisection(0,1,g,0.01)
not
f = @Bisection(0,1,g,0.01)
Best wishes
Torsten.

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2018 年 1 月 24 日

回答済み:

2018 年 1 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by