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:

Réponses (1)

Torsten
Torsten le 24 Jan 2018

0 votes

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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by