Why is my Muller Methods program fail?

1 次查看(过去 30 天)
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

采纳的回答

David Hill
David Hill 2022-2-10
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 个评论
Fauzanul Ardhi
Fauzanul Ardhi 2022-2-13
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Construct and Work with Object Arrays 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by