Uploaded by Muntaha Rahman

Math4522 Lab5

advertisement
Islamic University of Technology (IUT)
Organization of Islamic Cooperation (OIC)
Department of Electrical and Electronic Engineering (EEE)
Course No.
Course Name
Experiment No.
Experiment Name
: Math 4522
: Numerical Methods Lab.
: 05
: Introduction to Muller’s Method.
 Objective
To get familiarized with Muller’s Method to find the root of non-linear equation.
 Theory
o Muller’s Method
Muller's method is a root-finding algorithm, a numerical method for solving equations of the
form f ( x) = 0. It was first presented by David E. Muller in 1956. Muller's method is based
on the secant method, which constructs at every iteration a line through two points on the
graph of f .
Müller’s method projects a parabola through three points. The method consists of deriving
the coefficients of the parabola that goes through the three points. These coefficients can then
be substituted into the quadratic formula to obtain the point where the parabola intercepts the
x axis—that is, the root estimate. The approach is facilitated by writing the parabolic equation
in a convenient form,
(7.17)
f 2 ( x)  a( x  x2 )2  b( x  x2 )  c
We want this parabola to intersect the three points [ x0 , f ( x0 )],[ x1 , f ( x1 )], and [ x2 , f ( x2 )] . The
coefficients of Eq. can be evaluated by substituting each of the three points to give
f ( x0 )  a( x0  x2 )2  b( x0  x2 )  c
(7.18)
f ( x1 )  a( x1  x2 )  b( x1  x2 )  c
(7.19)
f ( x2 )  a( x2  x2 )2  b( x2  x2 )  c
(7.20)
2
Note that we have dropped the subscript “2” from the function for conciseness. Because we
have three equations, we can solve for the three unknown coefficients, a, b , and c . Because
two of the terms in the above equations are zero, it can be immediately solved for c  f ( x2 ) .
Thus, the coefficient c is merely equal to the function value evaluated at the third guess, x2 .
This result can then be substituted to yield two equations with two unknowns:
f ( x0 )  f ( x2 )  a( x0  x2 )2  b( x2  x2 )
(7.21)
f ( x1 )  f ( x2 )  a( x1  x2 )  b( x1  x2 )
(7.22)
2
Algebraic manipulation can then be used to solve for the remaining coefficients, a and b .
One way to do this involves defining a number of differences,
Lab sheet prepared by Md. Arif Hossain, Lecturer (EEE), Islamic University of Technology (IUT)
h0  x1  x2
h1  x2  x1
0 
f ( x1 )  f ( x0 )
x1  x0
(7.23)
f ( x2 )  f ( x1 )
x2  x1
These can be substituted which can be solved for a and b . The results can be summarized as
1 
a
1   0
h1  h0
b  ah1  1
(7.24-7.26)
c  f ( x2 )
To find the root, we apply the quadratic formula. However, because of potential round-off
error, rather than using the conventional form, we use the alternative formulation
2c
(7.27a)
x3  x2 
b  b 2  4ac
isolating the unknown x3 on the left side of the equal sign,
2c
x3  x2 
b  b 2  4ac
(7.27b)
Note that the use of the quadratic formula means that both real and complex roots can be
located. This is a major benefit of the method.

Demonstration
Example 7.2 of the book.
Problem Statement: Use Müller’s method with guesses of x0 , x1 , and x2 = 4.5, 5.5, and 5,
respectively, to determine a root of the equation f ( x)  x3  13x  12
% Type Coeff as "[ 1 2 3 ...]" i.e Row vector form."
% Enter the values according to above order.
% If polynomial is more than 1st order, it would ask for three initial
%guess for iteration. If you dont have any clue about value of root
% then just press enter when ask for guess, and it would use default value
% of [1 2 3].
% Please provide with three distinct numbers or else error message would
%be displayed.
%function Muller()
clc,
clear all
syms x
symbol
R_Accuracy = 1e-8;
A_x = 0;
initiallization
flag =1;
% variable x declared
% Equivalent to Maxerr
% Function
% Flag will be used for
Lab sheet prepared by Md. Arif Hossain, Lecturer (EEE), Islamic University of Technology (IUT)
terminating process
Root_index =0;
disp('Polynomial function of Order "n" is of type:a[1]X^n+a[2]X^(n-1)+
..+a[n]X^1+a[n+1]');
disp('Type Coeff as "[ 1 2 3 ...]" i.e Row vector form');
Coeff = input('Enter the coefficient in order? ');
[row_initial,col_initial] = size(Coeff);
for i = 1:col_initial
A_x = A_x + Coeff(i)*(x^(col_initial-i));
% Polynomial function
building
end
disp('Polynomial is : ');
disp(A_x)
while(flag)
[row,col] = size(Coeff);
if (col ==1)
flag =0;
elseif(col==2)
flag =0;
Root_index = Root_index + 1;
Root(Root_index)= -Coeff(2)/Coeff(1);
disp(['Root found:' num2str(-Coeff(2)/Coeff(1)) '']);
disp(' ')
elseif(col >= 3)
Guess = input('Give the three initial guess point [x0, x1, x2]: ');
if isempty(Guess)
%isempty(X) returns 1
if X is an empty array and 0 otherwise.
Guess = [1 2 3];
disp('Using default value [1 2 3]')
elseif(Guess == zeros(1,3))
break
end
disp(['Three initial guess are: ' num2str(Guess) ' ']);
for i = 1:100
h1 = Guess(2)-Guess(1);
%h0 = x1 ? x0
h2 = Guess(3)-Guess(2);
%h1 = x2 ? x1
d1 = (polyval(Coeff,Guess(2))-polyval(Coeff,Guess(1)))/h1; %?0
= f(x1) ? f(x0)/(x1-x0)
d2 = (polyval(Coeff,Guess(3))-polyval(Coeff,Guess(2)))/h2; %?1
= f(x2) ? f(x1)/(x2-x1)
d = (d2-d1)/(h1+h2);
%a = ?1 ? ?0/h1 + h0
b = d2 + h2*d;
%b = ah1 + ?1
Delta = sqrt(b^2-4*polyval(Coeff,Guess(3))*d);
%polyval(coeff,guess(3)=c), so delta=sqrt(b^2-4ac)
if (abs(b-Delta)<abs(b+d))
E = b + Delta;
%denominator of eq
7.27a
else
E = b - Delta;
%denominator of eq
7.27a
end
h = -2*polyval(Coeff,Guess(3))/E;
%equation 7.27a
p = Guess(3) + h;
%guess(3) is
equivalent to x2
if (abs(h) < R_Accuracy)
Factor = [1 -p];
Root_index = Root_index + 1;
Root(Root_index)= p;
disp(['Root found: ' num2str(p) ' ']);
disp(' ')
break;
else
Guess = [Guess(2) Guess(3) p];
Lab sheet prepared by Md. Arif Hossain, Lecturer (EEE), Islamic University of Technology (IUT)
end
if (i ==99)
disp('Method failed to find root!!!');
end
end
end
[Coeff,rem] = deconv(Coeff,Factor); %reduces the number of coeff and
finally makes the flag 0 to exit the function
end
disp(['Function has ' num2str(Root_index) ' roots, given as:']);
for i = 1:Root_index
disp(['Root no ' num2str(i) ' is ' num2str(Root(i)) ' .'])
end
disp('End of Program');
 Verification:
The result as obtained from the book should be -3, -1 and 4.
 Task in the Lab:
1. Modify the given code in such a way that in the command window you will see “Section-1”
but as soon as “Section-2” starts, “Section-1” will be cleared and so on. So at the end only
“Section-4” should exist in your command window.
 Task for the report:
1. Generate a code to solve problems using Bairstow’s Method. You can take help from the
internet. But after every line you should explain that line within comments. Make sure one
can fully understand your code by reading the comments.
Lab sheet prepared by Md. Arif Hossain, Lecturer (EEE), Islamic University of Technology (IUT)
Download