roots finding using muller method

37 ビュー (過去 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);
  1 件のコメント
shiv gaur
shiv gaur 2021 年 7 月 25 日
one working at a time

サインインしてコメントする。


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 Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by