Why is my Muller Methods program fail?

1 Ansicht (letzte 30 Tage)
Fauzanul Ardhi
Fauzanul Ardhi am 10 Feb. 2022
Kommentiert: Fauzanul Ardhi am 13 Feb. 2022
i tried to cunstruct muller method program for polinomial x^3-x^2+2*x-2 using initial guest x0=1.3 x1=1.5 and x2=2. When i try using excell, i get approriate result, x=1. Unfortunately, when i use my mathlab program, the result is different nor the expected roots of the polinomial. i hope someone can help me and explain whats wrong with my program.
From the deepest part of my heart, i'm kindly express my highest gratitude for your cooperation.
x=[1.3 1.5 2];
p=[1 -1 2 -2];
y=polyval(p,x);
es=0.0001;
ea=10;
while ea>es
h0=x(2)-x(1);
h1=x(3)-x(2);
delta0=(y(2)-y(1))/h0;
delta1=(y(3)-y(1))/h1;
a=(delta1-delta0)/h1+h0;
b=a*h1+delta1;
c=y(3);
rad=sqrt(b^2-4*a*c);
if abs(b+rad)>abs(b-rad)
den=b+rad;
else
den=b-rad;
end
x3=x(3)+(-2*c)/den;
ea=abs((x3-x(3))/x3);
x(1)=x(2);
x(2)=x(3);
x(3)=x3;
end
x3

Akzeptierte Antwort

David Hill
David Hill am 10 Feb. 2022
Not sure if you are doing divided differences correctly.
x=[1.3 1.5 2];%input x values
p=[1 -1 2 -2];%input polynomial
y=polyval(p,x);
es=1e-10;
ea=10;
c=3;
while ea>es
w=div_diff(p,x(c-2:c-1))+div_diff(p,x([c-2,c]))-div_diff(p,x(c-1:c));
Rad=sqrt(w^2-4*y(c)*div_diff(p,x(c-2:c)));
Div=[w+Rad,w-Rad];
[~,idx]=max(abs(Div));
Div=Div(idx);
x(c+1)=x(c)-2*y(c)/Div;
y(c+1)=polyval(p,x(c+1));
ea=abs((x(c+1)-x(c))/x(c));
c=c+1;
end
Anser=x(end);
function y=div_diff(p,x)
if length(x)==2
y=diff(polyval(p,x))/diff(x);
else
y=div_diff(p,x(2:end))-div_diff(p,x(1:2))/(x(2)-x(1));
end
end
  1 Kommentar
Fauzanul Ardhi
Fauzanul Ardhi am 13 Feb. 2022
ooh, i see. i think its also because i evaluate y before while loop, so its only give value for the initial guest. thanks a lot, sir.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by