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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!