Bisection method Need Help!

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:

Answers (1)

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.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 24 Jan 2018

Answered:

on 24 Jan 2018

Community Treasure Hunt

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

Start Hunting!