roots finding using muller method

조회 수: 100 (최근 30일)
shiv gaur
shiv gaur 2021년 7월 25일
댓글: Walter Roberson 2021년 8월 2일
only one root is showing suppose f(x)=x^2+1 only -i root is showing not +i
here this is program of muller method
function shik3
% t2=1e-6;
p0 = 10;
p1 = 20;
p2 = 30;
TOL = 10^-9;
N0 = 100;
format long;
h1 = p1 - p0;
h2 = p2 - p1;
DELTA1 = (f(p1) - f(p0))/h1;
DELTA2 = (f(p2) - f(p1))/h2;
d = (DELTA2 - DELTA1)/(h2 + h1);
i=3;
while i <= N0
b = DELTA2 + h2*d;
D = (b.^2 - 4*f(p2).*d).^(1/2);
if abs(b-D) < abs(b+D)
E = b + D;
else
E = b - D;
end
h = -2*f(p2)/E;
p = p2 + h;
if abs(h) < TOL
p
disp(p)
break
end
p0 = p1;
p1 = p2;
p2 = p;
h1 = p1 - p0;
h2 = p2 - p1;
DELTA1 = (f(p1) - f(p0))/h1;
DELTA2 = (f(p2) - f(p1))/h2;
d = (DELTA2 - DELTA1)/(h2 + h1);
i = i + 1;
disp(p)
%disp([imag(p) t2])
%plot(t2,real(p))
end
if i > N0
formatSpec = string('The method failed after N0 iterations,N0= %d \n');
fprintf(formatSpec,N0);
end
function y=f(x)
y=x^2+1 ;
end
end
  댓글 수: 2
Jan
Jan 2021년 7월 25일
Please edit your question. Do you see the pile of blank lines? Deleteing them and using the code block improves the readability. Thanks.
shiv gaur
shiv gaur 2021년 7월 25일
runing program only one root is showing

댓글을 달려면 로그인하십시오.

답변 (2개)

Chunru
Chunru 2021년 7월 25일
The Muller's method is supposed for finding the real solution. Your code is attempting to find the complex solution. I am wondering if it has any other side-effect.
The Muller's method is based on secant method (or in a similar way) to iteratively find the solution. It cannot guarantee to find all solutions of a functions. It just find a solution (normally real) within the specified interval.
For you code, you may find another solution by change the sign of the following line
% D = (b.^2 - 4*f(p2).*d).^(1/2);
D = -(b.^2 - 4*f(p2).*d).^(1/2);

Walter Roberson
Walter Roberson 2021년 8월 1일
Your program only ever tries to find one root. You have a while loop, but that while loop is only dealing with one root.
You have several options:
  1. As you are solving a polynomial with real-valued coefficients, all imaginary roots must occur as complex conjugates. So after you find one root, take its complex conjugate and test it to see whether it works as well
  2. rewrite the code to try several different initial guesses, and keep trying guesses until you reach a sanity limit or you have found as many unique roots as you think you should have
  3. rewrite your code to be working on a vector of guesses, and keep iterating until you reach a sanity limit or enough unique roots have reach tolerance. Note that if you fail to try enough different elements originally then you are not certain that enough of them will lead to unique roots.
  4. use a completely different algorithm, such a symbolic method
  댓글 수: 3
shiv gaur
shiv gaur 2021년 8월 2일
taking simple example
Walter Roberson
Walter Roberson 2021년 8월 2일
This looks like a homework problem, so you should be writing the code.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by