Bisection method Need Help!
Mostrar comentarios más antiguos
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:

Respuestas (1)
Torsten
el 24 de En. de 2018
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.
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!