Why is my Muller Methods program fail?

조회 수: 1 (최근 30일)
Fauzanul Ardhi
Fauzanul Ardhi 2022년 2월 10일
댓글: Fauzanul Ardhi 2022년 2월 13일
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에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by