Undefined function or variable 'fr' and 'xm'
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I am trying to do this exercise of finding a root by using the bisection method and the false position method. But, when compiling, it keeps saying this error. Can someone help me?
the code:
clear all clc
f =@(x)(1.67*cos(40.0))-(2.5*cos(x))+(1.83-cos((40.0-x)));
a0=input('Entre com a primeira aproximação a0:');
b0=input('Entre com a segunda aproximação b0:');
tol=input('Entre com o valor da tolerancia:');
while (abs(b0-a0)>tol)
xm =(a0+b0)/2;
if((f(a0)*f(xm)<0))
b0=xm
else
a0=xm
end
end
fprintf("A Raiz da equação pelo método da bissecção é= %f\n", xm);
%Regula Falsi
f1 = f(a0)
f2= f(b0)
while (abs(b0-a0)>tol)
fr = (((a0)*f1)-((b0)*f2))/(f2-f1);
y=f(fr);
if((f1*y>0))
a0=fr;
f1=y;
else
b0=fr;
f2=y;
end
end
fprintf("%f",fr);
0 Commenti
Risposte (1)
James Tursa
il 22 Set 2017
Modificato: James Tursa
il 22 Set 2017
Your bisection method changes a0 and b0, which are then fed into your false position method as the starting point. You need to remember the starting point and make sure you feed that same starting point into both methods.
Also, it a0 and b0 are really good guesses and pass the tol test immediately, you never set xm or fr.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!