SlideShare ist ein Scribd-Unternehmen logo
1 von 11
EC 313: Numerical Methods                            Mayank Awasthi
MATLAB Assignment – 1                               M. Tech, IIT Roorkee
                                                    (Communication Systems)

Ques1:

MATLAB routine which finds the coefficients of Lagrange polynomial is below:
%Implementing Lagrange Interpolating Formula
function l = lagranp(x,y)
N = length(x)-1; %the degree of polynomial
l = 0;
for m = 1:N + 1
P = 1;
for k = 1:N + 1
%Multiplication of two polynomials corresponds to convolution of their
coefficients.
if k ~= m

%”linconv” function created by own.
P = linconv(P,[1 -x(k)])/(x(m)-x(k));
end
end
l = l + y(m)*P; %Lagrange polynomial coefficients
end

MATLAB routine for Linear Convolution:
%Linear convolution of sequence using formula
function s=linconv(x,h)
N=length(x);
M=length(h);
for n=1:N+M-1
  s(n)=0;
for k=1:M
  a=n-k;
if a<0
   y(k)=0;
elseif k>N
    y(k)=0;
elseif a<M
   y(k)=x(k)*h(a+1);
else
   y(k)=0;
end
   s(n)=s(n)+y(k);
end
end
MATLAB routine which finds the coefficients of Newton polynomial is below:

%Implementing the Newton divided difference formula
function n = newtonp(x,y)
N = length(x)-1;
f = zeros(N+1,1);
f(1:N+1,1) = y;
for k = 2:N + 1
for m = 1: N + 2 - k %Divided Difference
f(m,k) = (f(m + 1,k - 1) - f(m,k - 1))/(x(m + k - 1)- x(m));
end
end
a = f(1,:);
n = a(N+1);
for k =N:-1:1
%Nested multiplication form for better computation efficiency
%a_k=f(x0,x1,……….xk)
n = [n a(k)] - [0 n*x(k)]; %f(x)*(a_k*(x - x(k - 1))+a_k – 1)
end

>> x=[1 3 4];                 Calculating the polynomial using both routines for
>> y=[1 27 64];               given data.

>> coefflag = lagranp(x,y)
coefflag =
8.0000 -19.0000 12.0000           So required polynomial we get 8x2 – 19x + 12

>> coeffnew = newtonp(x,y)
coeffnew =
8 -19 12
Ques2:

a)- For Straight Line: deg(Polynomial)=1
    So using Newton or Lagrange routine we can get the coeff. Of polynomial as
below:

>> x= [1970 1990] ;
>> y= [3707475887 5281653820] ;
>> nc=newtonp(x,y)
nc =
1.0e+011 *
0.0008 -1.5135

>> v0=polyval(nc,1980)

v0 =                                  % 1980 Population using straight line
4.4946e+009

b)- For parabola: deg(Polynomial)=2

>> x= [1960 1970 1990];
>> y= [3039585530 3707475887 5281653820];
>> nc= newtonp(x,y)
nc =
1.0e+012 *
 0.0000 -0.0015 1.4063

>> v1=polyval(nc,1980)                % 1980 Population parabola

v1 =
4.4548e+009

c)- For cubic curve deg(Polynomial)

>> x= [1960 1970 1990 2000];
>> y= [3039585530 3707475887 5281653820 6079603571];
>> nc=newtonp(x,y)
nc =
1.0e+013 *
 -0.0000 0.0000 -0.0107 7.0777

>> v3=polyval(nc,1980)                 % 1980 Population using cubic curve

v3 =
4.4729e+009
Ques4:

MATLAB routine which computes the divide difference coefficient is below:

%matalb script for computing dividedifference coefff.
function ddc = dividediff(x,y)
N = length(x)-1;
f = zeros(N+1,1);
f(1:N+1,1) = y;
for k = 2:N + 1
for m = 1: N + 2 - k %Divided Difference
f(m,k) = (f(m + 1,k - 1) - f(m,k - 1))/(x(m + k - 1)- x(m));
end
ddc=f(1,:);
end
end

Calculating the divide difference coefficients.
>> x=[1 2 4 5 7 9];
>> y=[2 3 8 6 14 6];
>> divide_diff_coeff = dividediff(x,y)

divide_diff_coeff =

  2.0000 1.0000 0.5000 -0.5000           0.2000 -0.0518

Now Calculating the polynomial using Newton method routine used in Ques1.
>> x=[1 2 4 5 7 9];
>> y=[2 3 8 6 14 6];
>> nc= newtonp(x,y)

nc =

 -0.0518 1.1839 -9.7875 35.6018 -53.4464 28.5000

Required Polynomial is
-0.0518x5 + 1.1839x4 -9.7875x3 + 35.6018x2-53.4464x +28.5000

v0=p(1.5), v1=p(3.7), v2=p(6.6), v3=p(9.5)

>> v0=polyval(nc,1.5)                             >> v2=polyval(nc,6.6)
v0 =                                              v2 =
1.0020                                            10.6441

>> v1=polyval(nc,3.7)                             >> v3=polyval(nc,9.5)
v1 =                                              v3 =
8.3474                               -21.6454

Plotting Graph
>> x=[1 2 4 5 7 9];
>> y=[2 3 8 6 14 6];
>> nc= newtonp(x,y)

nc =

 -0.0518 1.1839 -9.7875 35.6018 -53.4464 28.5000

>> m=[0:10];
>> n=polyval(nc,m)

n=
28.5000 2.0000 3.0000 7.6286 8.0000 6.0000      7.0714 14.0000 20.7000
6.0000 -72.5714

>> plot(m,n)
Ques5 :
Bisection Method :
%Bisection method to solve Non-linear equations.
function [x] = bisct(f,a,b,z,MaxIter)
fa = feval(f,a);
fb = feval(f,b);
if fa*fb > 0
error('We must have f(a)f(b)<0!');
end
for k = 1:MaxIter
xx(k) = (a + b)/2;
fx =feval(f,xx(k));
err = (b-a)/2;
if abs(err)<z
break;
elseif fx*fa > 0
a = xx(k); fa = fx;
else b = xx(k);
end
x = xx(k);
end
fprintf('The Interval in which root lie is %d   %dn',a,b)
fprintf('Iteration Required is %dn',k)
fprintf('The approx. error is %dn',err)
end

Regula Falsi Method :
%Implementing Regula Falsi algorithm.
function [] = falsp(f,a,b,z,MaxIter)
fa =feval(f,a);
fb=feval(f,b);
if fa*fb > 0
error('We must have f(a)f(b)<0!');
end
for k = 1: MaxIter
xx(k) = (a*fb-b*fa)/(fb-fa);
fx = feval(f,xx(k));
err = max(abs(xx(k) - a),abs(b - xx(k)));
if err<z
    break;
elseif fx*fa > 0
    a = xx(k);
    fa = fx;
else b = xx(k);
     fb = fx;
end
end
x = xx(k);
fprintf('The Interval in which root lie is %d   %dn',a,b)
fprintf('Iteration Required is %dn',k)
fprintf('The approx. error is %dn',err)
end
Modified Regula Falsi Method :
%Implementing Modified Regula Falsi algorithm
function [] = mrfalsp(f,a,b,z,MaxIter)
fa =feval(f,a);
fb=feval(f,b);
F=fa;
G=fb;

if fa*fb > 0
error('We must have f(a)f(b)<0!');
end
xx(1)=a/2;
for k = 1: MaxIter
xx(k+1) = (a*G-b*F)/(G-F);
fx = feval(f,xx(k+1));
err = max(abs(xx(k) - a),abs(b - xx(k)));
if err<z
    break;
end
if fx*fa > 0
    a = xx(k+1);
    fa = fx;
elseif feval(f,xx(k))*feval(f,xx(k+1))>0
    F=F/2;
    end
if fx*fa < 0
    b = xx(k+1);
     fb = fx;
    elseif feval(f,xx(k))*feval(f,xx(k+1))>0
    G=G/2;
    end
end
fprintf('The Interval in which root lie is %d %dn',a,b)
fprintf('Iteration Required is %dn',k)
fprintf('The approx. error is %dn',err)
end
Newton Raphson Meyhod :
%Implementing Newton Raphson Method
function [] = newton(f,df,x0,z,MaxIter)
xx(1) = x0;
fx = feval(f,x0);
for k = 1: MaxIter
if ~isnumeric(df)
    dfdx = feval(df,xx(k));end
dx = -fx/dfdx;
xx(k+1) = xx(k)+dx;
fx = feval(f,xx(k + 1));
a= xx;
if abs(dx) < z
break; end
end
l=length(a);
fprintf('The approx. Root is %dnn',x);
fprintf('Iteration Required is %dn',k)
end

Now calculating the roots of given polynomials
a)- exp(-x)-sin(x)                  assuming interval (0,1) & Max_Iteration=50

>> f=inline('exp(-x)-sin(x)');   %matlab command to define function
>> df=inline('-exp(-x)-cos(x)'); %derivative of f

1)- Bisection method:
>> bisct(f,0,1,1e-6,50)
The Interval in which root lie is 5.885315e-001   5.885334e-001
Iteration Required is 20
The approx. error is 9.536743e-007

2)- Regula Falsi:
>> rfalsi(f,0,1,1e-6,50)
The Interval in which root lie is 0 5.885327e-001
Iteration Required is 50
The approx. error is 5.885327e-001

3)- Modified Regula Falsi:
>> mrfalsi(f,0,1.0,1e-6,50)
The Interval in which root lie is 5.885315e-001 5.885342e-001
Iteration Required is 23
The approx. error is 3.976230e-006

4)- Newton Raphson Method:
>> newtonrap(f,df,.2,1e-6,50)
The approx. Root is 5.885327e-001
Iteration Required is 4
b)- x- exp(-(x^2))                     assuming interval (0,1) & Max_Iteration=50
>> f=inline('x-exp(-(x^2))');          %matlab command to define function
>> df=inline('1+2*x*exp(-(x^2))');     %derivative of f

1)- Bisection method:
>> bisct(f,0,1,1e-6,50)
The Interval in which root lie is 6.529179e-001 6.529198e-001
Iteration Required is 20
The approx. error is 9.536743e-007

2)- Regula Falsi:
>> rfalsi(f,0,1.0,1e-6,50)
The Interval in which root lie is 6.529186e-001   6.534421e-001
Iteration Required is 50
The approx. error is 5.234929e-004

3)- Modified Regula Falsi:
>> mrfalsi(f,0,1.0,1e-6,50)
The Interval in which root lie is 6.529059e-001 6.529198e-001
Iteration Required is 25
The approx. error is 2.490377e-005

4)- Newton Raphson Method:
>> newtonrap(f,df,.5,1e-6,50)
The approx. Root is 6.529186e-001
Iteration Required is 4

c)- (x^3)-x-2                assuming interval (-1,2) & Max_Iteration=50
>> f=inline('(x^3)-x-2')     %matlab command to define function
>> df=inline('3*(x^2)-1');   %derivative of f

1)- Bisection method:
>> bisct(f,-1,2,1e-6,50)
The Interval in which root lie is 1.521379e+000 1.521382e+000
Iteration Required is 22
The approx. error is 2.861023e-006

2)- Regula Falsi:
>> rfalsi(f,-1,2,1e-6,50)
The Interval in which root lie is 1.521380e+000 2
Iteration Required is 50
The approx. error is 4.786203e-001
3)- Modified Regula Falsi:
>> mrfalsi(f,-1,2,1e-6,50)
The Interval in which root lie is 1.521356e+000 1.521386e+000
Iteration Required is 28
The approx. error is 6.021365e-005

4)- Newton Raphson Method:
>> newtonrap(f,df,1,1e-6,50)
The approx. Root is 1.521380e+000
Iteration Required is 6



Ques3:

For finding the the smallest positive guess for which Newton method diverges,
we can use Newton Raphson method check for various guess as the root start
diverging we can say that that is our required positive guess.


Assuming z-1e-006        % Tolerance parameter

>> f=inline('atan(x)')

f=

     Inline function:
     f(x) = atan(x)

>> df=inline('1/(1+x^2)')

df =

     Inline function:
     df(x) = 1/(1+x^2)

>> newtonrap(f,df,1,1e-6,1000)
The approx. Root is 0
Iteration Required is 5

>> newtonrap(f,df,1.1,1e-6,1000)
The approx. Root is -1.803121e-019
Iteration Required is 5
>> newtonrap(f,df,1.2,1e-6,1000)
The approx. Root is 0
Iteration Required is 6

>> newtonrap(f,df,1.3,1e-6,1000)
The approx. Root is 0
Iteration Required is 7

>> newtonrap(f,df,1.38,1e-6,1000)
The approx. Root is 0
Iteration Required is 9

>> newtonrap(f,df,1.39,1e-6,1000)
The approx. Root is 0
Iteration Required is 11

>> newtonrap(f,df,1.4,1e-6,1000)
Warning: Divide by zero.
> In newtonrap at 8
Warning: Divide by zero.
> In newtonrap at 8
The approx. Root is NaN
Iteration Required is 1000

From the above data we get
Since at 1.4 there is divide by zero error so beyond 1.4 function (‘atanx’) may
diverge.
Smallest positive guess will be 1.4.

Weitere ähnliche Inhalte

Was ist angesagt?

6. Vectors – Data Frames
6. Vectors – Data Frames6. Vectors – Data Frames
6. Vectors – Data FramesFAO
 
3.1 derivative of a function
3.1 derivative of a function3.1 derivative of a function
3.1 derivative of a functionbtmathematics
 
Overlap save method and overlap add method in dsp
Overlap save method and overlap add method in dspOverlap save method and overlap add method in dsp
Overlap save method and overlap add method in dspchitra raju
 
Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics Alexander Litvinenko
 
Approximate Integration
Approximate IntegrationApproximate Integration
Approximate IntegrationSilvius
 
Overlap Add, Overlap Save(digital signal processing)
Overlap Add, Overlap Save(digital signal processing)Overlap Add, Overlap Save(digital signal processing)
Overlap Add, Overlap Save(digital signal processing)Gourab Ghosh
 
111015 tokyo scipy2_discussionquestionaire_i_python
111015 tokyo scipy2_discussionquestionaire_i_python111015 tokyo scipy2_discussionquestionaire_i_python
111015 tokyo scipy2_discussionquestionaire_i_pythonShohei Hido
 
Numerical_Methods_Simpson_Rule
Numerical_Methods_Simpson_RuleNumerical_Methods_Simpson_Rule
Numerical_Methods_Simpson_RuleAlex_5991
 
13. Cubist
13. Cubist13. Cubist
13. CubistFAO
 
Advanced matlab codigos matematicos
Advanced matlab codigos matematicosAdvanced matlab codigos matematicos
Advanced matlab codigos matematicosKmilo Bolaños
 
Final Exam Review (Integration)
Final Exam Review (Integration)Final Exam Review (Integration)
Final Exam Review (Integration)Matthew Leingang
 
Using R Tool for Probability and Statistics
Using R Tool for Probability and Statistics Using R Tool for Probability and Statistics
Using R Tool for Probability and Statistics nazlitemu
 
Solution manual for theory and applications of digital speech processing lawr...
Solution manual for theory and applications of digital speech processing lawr...Solution manual for theory and applications of digital speech processing lawr...
Solution manual for theory and applications of digital speech processing lawr...zammok
 
Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)asghar123456
 

Was ist angesagt? (19)

Number system converted
Number system convertedNumber system converted
Number system converted
 
6. Vectors – Data Frames
6. Vectors – Data Frames6. Vectors – Data Frames
6. Vectors – Data Frames
 
3.1 derivative of a function
3.1 derivative of a function3.1 derivative of a function
3.1 derivative of a function
 
Overlap save method and overlap add method in dsp
Overlap save method and overlap add method in dspOverlap save method and overlap add method in dsp
Overlap save method and overlap add method in dsp
 
Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics
 
Approximate Integration
Approximate IntegrationApproximate Integration
Approximate Integration
 
Overlap Add, Overlap Save(digital signal processing)
Overlap Add, Overlap Save(digital signal processing)Overlap Add, Overlap Save(digital signal processing)
Overlap Add, Overlap Save(digital signal processing)
 
Digital signal processing
Digital signal processingDigital signal processing
Digital signal processing
 
111015 tokyo scipy2_discussionquestionaire_i_python
111015 tokyo scipy2_discussionquestionaire_i_python111015 tokyo scipy2_discussionquestionaire_i_python
111015 tokyo scipy2_discussionquestionaire_i_python
 
Numerical_Methods_Simpson_Rule
Numerical_Methods_Simpson_RuleNumerical_Methods_Simpson_Rule
Numerical_Methods_Simpson_Rule
 
Chemistry Assignment Help
Chemistry Assignment Help Chemistry Assignment Help
Chemistry Assignment Help
 
13. Cubist
13. Cubist13. Cubist
13. Cubist
 
CLIM Fall 2017 Course: Statistics for Climate Research, Spatial Data: Models ...
CLIM Fall 2017 Course: Statistics for Climate Research, Spatial Data: Models ...CLIM Fall 2017 Course: Statistics for Climate Research, Spatial Data: Models ...
CLIM Fall 2017 Course: Statistics for Climate Research, Spatial Data: Models ...
 
Advanced matlab codigos matematicos
Advanced matlab codigos matematicosAdvanced matlab codigos matematicos
Advanced matlab codigos matematicos
 
Codecomparaison
CodecomparaisonCodecomparaison
Codecomparaison
 
Final Exam Review (Integration)
Final Exam Review (Integration)Final Exam Review (Integration)
Final Exam Review (Integration)
 
Using R Tool for Probability and Statistics
Using R Tool for Probability and Statistics Using R Tool for Probability and Statistics
Using R Tool for Probability and Statistics
 
Solution manual for theory and applications of digital speech processing lawr...
Solution manual for theory and applications of digital speech processing lawr...Solution manual for theory and applications of digital speech processing lawr...
Solution manual for theory and applications of digital speech processing lawr...
 
Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)
 

Andere mochten auch

MITCOE 2011-12 conm-submission
MITCOE 2011-12 conm-submissionMITCOE 2011-12 conm-submission
MITCOE 2011-12 conm-submissionAshutosh Katti
 
Interval Newton Method
Interval Newton MethodInterval Newton Method
Interval Newton MethodJohannes K
 
آموزش محاسبات عددی - بخش ششم
آموزش محاسبات عددی - بخش ششمآموزش محاسبات عددی - بخش ششم
آموزش محاسبات عددی - بخش ششمfaradars
 
Euler Method using MATLAB
Euler Method using MATLABEuler Method using MATLAB
Euler Method using MATLABM.Ahmed Waqas
 
metode euler
metode eulermetode euler
metode eulerRuth Dian
 
MATLAB ODE
MATLAB ODEMATLAB ODE
MATLAB ODEKris014
 
Taylor and maclaurian series
Taylor and maclaurian seriesTaylor and maclaurian series
Taylor and maclaurian seriesNishant Patel
 
Introduction to Numerical Methods for Differential Equations
Introduction to Numerical Methods for Differential EquationsIntroduction to Numerical Methods for Differential Equations
Introduction to Numerical Methods for Differential Equationsmatthew_henderson
 
Exp 5 (1)5. Newton Raphson load flow analysis Matlab Software
Exp 5 (1)5.	Newton Raphson load flow analysis Matlab SoftwareExp 5 (1)5.	Newton Raphson load flow analysis Matlab Software
Exp 5 (1)5. Newton Raphson load flow analysis Matlab SoftwareShweta Yadav
 
Numerical Analysis (Solution of Non-Linear Equations) part 2
Numerical Analysis (Solution of Non-Linear Equations) part 2Numerical Analysis (Solution of Non-Linear Equations) part 2
Numerical Analysis (Solution of Non-Linear Equations) part 2Asad Ali
 
numericai matmatic matlab uygulamalar ali abdullah
numericai matmatic  matlab  uygulamalar ali abdullahnumericai matmatic  matlab  uygulamalar ali abdullah
numericai matmatic matlab uygulamalar ali abdullahAli Abdullah
 
NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...
NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...
NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...Parhamsagharchi
 
Least square method
Least square methodLeast square method
Least square methodSomya Bagai
 
Implementation of Wireless Channel Model in MATLAB: Simplified
Implementation of Wireless Channel Model in MATLAB: SimplifiedImplementation of Wireless Channel Model in MATLAB: Simplified
Implementation of Wireless Channel Model in MATLAB: SimplifiedRosdiadee Nordin
 
Matlab for Electrical Engineers
Matlab for Electrical EngineersMatlab for Electrical Engineers
Matlab for Electrical EngineersManish Joshi
 

Andere mochten auch (18)

Exercício mme
Exercício mmeExercício mme
Exercício mme
 
MITCOE 2011-12 conm-submission
MITCOE 2011-12 conm-submissionMITCOE 2011-12 conm-submission
MITCOE 2011-12 conm-submission
 
Interval Newton Method
Interval Newton MethodInterval Newton Method
Interval Newton Method
 
Adaptive signal processing simon haykins
Adaptive signal processing simon haykinsAdaptive signal processing simon haykins
Adaptive signal processing simon haykins
 
آموزش محاسبات عددی - بخش ششم
آموزش محاسبات عددی - بخش ششمآموزش محاسبات عددی - بخش ششم
آموزش محاسبات عددی - بخش ششم
 
Euler Method using MATLAB
Euler Method using MATLABEuler Method using MATLAB
Euler Method using MATLAB
 
metode euler
metode eulermetode euler
metode euler
 
MATLAB ODE
MATLAB ODEMATLAB ODE
MATLAB ODE
 
Taylor and maclaurian series
Taylor and maclaurian seriesTaylor and maclaurian series
Taylor and maclaurian series
 
Introduction to Numerical Methods for Differential Equations
Introduction to Numerical Methods for Differential EquationsIntroduction to Numerical Methods for Differential Equations
Introduction to Numerical Methods for Differential Equations
 
Apostila de matlab
Apostila de matlabApostila de matlab
Apostila de matlab
 
Exp 5 (1)5. Newton Raphson load flow analysis Matlab Software
Exp 5 (1)5.	Newton Raphson load flow analysis Matlab SoftwareExp 5 (1)5.	Newton Raphson load flow analysis Matlab Software
Exp 5 (1)5. Newton Raphson load flow analysis Matlab Software
 
Numerical Analysis (Solution of Non-Linear Equations) part 2
Numerical Analysis (Solution of Non-Linear Equations) part 2Numerical Analysis (Solution of Non-Linear Equations) part 2
Numerical Analysis (Solution of Non-Linear Equations) part 2
 
numericai matmatic matlab uygulamalar ali abdullah
numericai matmatic  matlab  uygulamalar ali abdullahnumericai matmatic  matlab  uygulamalar ali abdullah
numericai matmatic matlab uygulamalar ali abdullah
 
NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...
NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...
NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...
 
Least square method
Least square methodLeast square method
Least square method
 
Implementation of Wireless Channel Model in MATLAB: Simplified
Implementation of Wireless Channel Model in MATLAB: SimplifiedImplementation of Wireless Channel Model in MATLAB: Simplified
Implementation of Wireless Channel Model in MATLAB: Simplified
 
Matlab for Electrical Engineers
Matlab for Electrical EngineersMatlab for Electrical Engineers
Matlab for Electrical Engineers
 

Ähnlich wie EC 313 Numerical Methods: Root Finding Techniques in MATLAB

Natural and Clamped Cubic Splines
Natural and Clamped Cubic SplinesNatural and Clamped Cubic Splines
Natural and Clamped Cubic SplinesMark Brandao
 
Fourier series example
Fourier series exampleFourier series example
Fourier series exampleAbi finni
 
Applied numerical methods lec10
Applied numerical methods lec10Applied numerical methods lec10
Applied numerical methods lec10Yasser Ahmed
 
Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)asghar123456
 
Non linearequationsmatlab
Non linearequationsmatlabNon linearequationsmatlab
Non linearequationsmatlabsheetslibrary
 
Solution of non-linear equations
Solution of non-linear equationsSolution of non-linear equations
Solution of non-linear equationsZunAib Ali
 
Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdfIncorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdfaartechindia
 
Matlab polynimials and curve fitting
Matlab polynimials and curve fittingMatlab polynimials and curve fitting
Matlab polynimials and curve fittingAmeen San
 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programmingAhmed Moawad
 
2. Fixed Point Iteration.pptx
2. Fixed Point Iteration.pptx2. Fixed Point Iteration.pptx
2. Fixed Point Iteration.pptxsaadhaq6
 
Chapter 1 (math 1)
Chapter 1 (math 1)Chapter 1 (math 1)
Chapter 1 (math 1)Amr Mohamed
 
curve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptxcurve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptxabelmeketa
 
SIAM - Minisymposium on Guaranteed numerical algorithms
SIAM - Minisymposium on Guaranteed numerical algorithmsSIAM - Minisymposium on Guaranteed numerical algorithms
SIAM - Minisymposium on Guaranteed numerical algorithmsJagadeeswaran Rathinavel
 

Ähnlich wie EC 313 Numerical Methods: Root Finding Techniques in MATLAB (20)

Natural and Clamped Cubic Splines
Natural and Clamped Cubic SplinesNatural and Clamped Cubic Splines
Natural and Clamped Cubic Splines
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
 
Applied numerical methods lec10
Applied numerical methods lec10Applied numerical methods lec10
Applied numerical methods lec10
 
05_AJMS_332_21.pdf
05_AJMS_332_21.pdf05_AJMS_332_21.pdf
05_AJMS_332_21.pdf
 
Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)
 
Non linearequationsmatlab
Non linearequationsmatlabNon linearequationsmatlab
Non linearequationsmatlab
 
Solution of non-linear equations
Solution of non-linear equationsSolution of non-linear equations
Solution of non-linear equations
 
Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdfIncorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
 
Matlab polynimials and curve fitting
Matlab polynimials and curve fittingMatlab polynimials and curve fitting
Matlab polynimials and curve fitting
 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programming
 
AJMS_389_22.pdf
AJMS_389_22.pdfAJMS_389_22.pdf
AJMS_389_22.pdf
 
Multirate sim
Multirate simMultirate sim
Multirate sim
 
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
 
Mit6 094 iap10_lec03
Mit6 094 iap10_lec03Mit6 094 iap10_lec03
Mit6 094 iap10_lec03
 
2. Fixed Point Iteration.pptx
2. Fixed Point Iteration.pptx2. Fixed Point Iteration.pptx
2. Fixed Point Iteration.pptx
 
Chapter 1 (math 1)
Chapter 1 (math 1)Chapter 1 (math 1)
Chapter 1 (math 1)
 
curve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptxcurve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptx
 
Application of derivative
Application of derivativeApplication of derivative
Application of derivative
 
5 numerical analysis
5 numerical analysis5 numerical analysis
5 numerical analysis
 
SIAM - Minisymposium on Guaranteed numerical algorithms
SIAM - Minisymposium on Guaranteed numerical algorithmsSIAM - Minisymposium on Guaranteed numerical algorithms
SIAM - Minisymposium on Guaranteed numerical algorithms
 

Mehr von Department of Telecommunications, Ministry of Communication & IT (INDIA) (8)

Workshop proposal
Workshop proposalWorkshop proposal
Workshop proposal
 
Feeding system for disabled report
Feeding system for disabled reportFeeding system for disabled report
Feeding system for disabled report
 
Design ideas mayank
Design ideas mayankDesign ideas mayank
Design ideas mayank
 
Pdpm,mayank awasthi,jabalpur,i it kanpur, servo motor,keil code
Pdpm,mayank awasthi,jabalpur,i it kanpur, servo motor,keil codePdpm,mayank awasthi,jabalpur,i it kanpur, servo motor,keil code
Pdpm,mayank awasthi,jabalpur,i it kanpur, servo motor,keil code
 
Analogic
AnalogicAnalogic
Analogic
 
jacobi method, gauss siedel for solving linear equations
jacobi method, gauss siedel for solving linear equationsjacobi method, gauss siedel for solving linear equations
jacobi method, gauss siedel for solving linear equations
 
An Introduction To Speech Recognition
An Introduction To Speech RecognitionAn Introduction To Speech Recognition
An Introduction To Speech Recognition
 
Numerical Methods Solving Linear Equations
Numerical Methods Solving Linear EquationsNumerical Methods Solving Linear Equations
Numerical Methods Solving Linear Equations
 

Kürzlich hochgeladen

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Kürzlich hochgeladen (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

EC 313 Numerical Methods: Root Finding Techniques in MATLAB

  • 1. EC 313: Numerical Methods Mayank Awasthi MATLAB Assignment – 1 M. Tech, IIT Roorkee (Communication Systems) Ques1: MATLAB routine which finds the coefficients of Lagrange polynomial is below: %Implementing Lagrange Interpolating Formula function l = lagranp(x,y) N = length(x)-1; %the degree of polynomial l = 0; for m = 1:N + 1 P = 1; for k = 1:N + 1 %Multiplication of two polynomials corresponds to convolution of their coefficients. if k ~= m %”linconv” function created by own. P = linconv(P,[1 -x(k)])/(x(m)-x(k)); end end l = l + y(m)*P; %Lagrange polynomial coefficients end MATLAB routine for Linear Convolution: %Linear convolution of sequence using formula function s=linconv(x,h) N=length(x); M=length(h); for n=1:N+M-1 s(n)=0; for k=1:M a=n-k; if a<0 y(k)=0; elseif k>N y(k)=0; elseif a<M y(k)=x(k)*h(a+1); else y(k)=0; end s(n)=s(n)+y(k); end end
  • 2. MATLAB routine which finds the coefficients of Newton polynomial is below: %Implementing the Newton divided difference formula function n = newtonp(x,y) N = length(x)-1; f = zeros(N+1,1); f(1:N+1,1) = y; for k = 2:N + 1 for m = 1: N + 2 - k %Divided Difference f(m,k) = (f(m + 1,k - 1) - f(m,k - 1))/(x(m + k - 1)- x(m)); end end a = f(1,:); n = a(N+1); for k =N:-1:1 %Nested multiplication form for better computation efficiency %a_k=f(x0,x1,……….xk) n = [n a(k)] - [0 n*x(k)]; %f(x)*(a_k*(x - x(k - 1))+a_k – 1) end >> x=[1 3 4]; Calculating the polynomial using both routines for >> y=[1 27 64]; given data. >> coefflag = lagranp(x,y) coefflag = 8.0000 -19.0000 12.0000 So required polynomial we get 8x2 – 19x + 12 >> coeffnew = newtonp(x,y) coeffnew = 8 -19 12
  • 3. Ques2: a)- For Straight Line: deg(Polynomial)=1 So using Newton or Lagrange routine we can get the coeff. Of polynomial as below: >> x= [1970 1990] ; >> y= [3707475887 5281653820] ; >> nc=newtonp(x,y) nc = 1.0e+011 * 0.0008 -1.5135 >> v0=polyval(nc,1980) v0 = % 1980 Population using straight line 4.4946e+009 b)- For parabola: deg(Polynomial)=2 >> x= [1960 1970 1990]; >> y= [3039585530 3707475887 5281653820]; >> nc= newtonp(x,y) nc = 1.0e+012 * 0.0000 -0.0015 1.4063 >> v1=polyval(nc,1980) % 1980 Population parabola v1 = 4.4548e+009 c)- For cubic curve deg(Polynomial) >> x= [1960 1970 1990 2000]; >> y= [3039585530 3707475887 5281653820 6079603571]; >> nc=newtonp(x,y) nc = 1.0e+013 * -0.0000 0.0000 -0.0107 7.0777 >> v3=polyval(nc,1980) % 1980 Population using cubic curve v3 =
  • 4. 4.4729e+009 Ques4: MATLAB routine which computes the divide difference coefficient is below: %matalb script for computing dividedifference coefff. function ddc = dividediff(x,y) N = length(x)-1; f = zeros(N+1,1); f(1:N+1,1) = y; for k = 2:N + 1 for m = 1: N + 2 - k %Divided Difference f(m,k) = (f(m + 1,k - 1) - f(m,k - 1))/(x(m + k - 1)- x(m)); end ddc=f(1,:); end end Calculating the divide difference coefficients. >> x=[1 2 4 5 7 9]; >> y=[2 3 8 6 14 6]; >> divide_diff_coeff = dividediff(x,y) divide_diff_coeff = 2.0000 1.0000 0.5000 -0.5000 0.2000 -0.0518 Now Calculating the polynomial using Newton method routine used in Ques1. >> x=[1 2 4 5 7 9]; >> y=[2 3 8 6 14 6]; >> nc= newtonp(x,y) nc = -0.0518 1.1839 -9.7875 35.6018 -53.4464 28.5000 Required Polynomial is -0.0518x5 + 1.1839x4 -9.7875x3 + 35.6018x2-53.4464x +28.5000 v0=p(1.5), v1=p(3.7), v2=p(6.6), v3=p(9.5) >> v0=polyval(nc,1.5) >> v2=polyval(nc,6.6) v0 = v2 = 1.0020 10.6441 >> v1=polyval(nc,3.7) >> v3=polyval(nc,9.5) v1 = v3 =
  • 5. 8.3474 -21.6454 Plotting Graph >> x=[1 2 4 5 7 9]; >> y=[2 3 8 6 14 6]; >> nc= newtonp(x,y) nc = -0.0518 1.1839 -9.7875 35.6018 -53.4464 28.5000 >> m=[0:10]; >> n=polyval(nc,m) n= 28.5000 2.0000 3.0000 7.6286 8.0000 6.0000 7.0714 14.0000 20.7000 6.0000 -72.5714 >> plot(m,n)
  • 6. Ques5 : Bisection Method : %Bisection method to solve Non-linear equations. function [x] = bisct(f,a,b,z,MaxIter) fa = feval(f,a); fb = feval(f,b); if fa*fb > 0 error('We must have f(a)f(b)<0!'); end for k = 1:MaxIter xx(k) = (a + b)/2; fx =feval(f,xx(k)); err = (b-a)/2; if abs(err)<z break; elseif fx*fa > 0 a = xx(k); fa = fx; else b = xx(k); end x = xx(k); end fprintf('The Interval in which root lie is %d %dn',a,b) fprintf('Iteration Required is %dn',k) fprintf('The approx. error is %dn',err) end Regula Falsi Method : %Implementing Regula Falsi algorithm. function [] = falsp(f,a,b,z,MaxIter) fa =feval(f,a); fb=feval(f,b); if fa*fb > 0 error('We must have f(a)f(b)<0!'); end for k = 1: MaxIter xx(k) = (a*fb-b*fa)/(fb-fa); fx = feval(f,xx(k)); err = max(abs(xx(k) - a),abs(b - xx(k))); if err<z break; elseif fx*fa > 0 a = xx(k); fa = fx; else b = xx(k); fb = fx; end end x = xx(k); fprintf('The Interval in which root lie is %d %dn',a,b) fprintf('Iteration Required is %dn',k) fprintf('The approx. error is %dn',err) end
  • 7. Modified Regula Falsi Method : %Implementing Modified Regula Falsi algorithm function [] = mrfalsp(f,a,b,z,MaxIter) fa =feval(f,a); fb=feval(f,b); F=fa; G=fb; if fa*fb > 0 error('We must have f(a)f(b)<0!'); end xx(1)=a/2; for k = 1: MaxIter xx(k+1) = (a*G-b*F)/(G-F); fx = feval(f,xx(k+1)); err = max(abs(xx(k) - a),abs(b - xx(k))); if err<z break; end if fx*fa > 0 a = xx(k+1); fa = fx; elseif feval(f,xx(k))*feval(f,xx(k+1))>0 F=F/2; end if fx*fa < 0 b = xx(k+1); fb = fx; elseif feval(f,xx(k))*feval(f,xx(k+1))>0 G=G/2; end end fprintf('The Interval in which root lie is %d %dn',a,b) fprintf('Iteration Required is %dn',k) fprintf('The approx. error is %dn',err) end
  • 8. Newton Raphson Meyhod : %Implementing Newton Raphson Method function [] = newton(f,df,x0,z,MaxIter) xx(1) = x0; fx = feval(f,x0); for k = 1: MaxIter if ~isnumeric(df) dfdx = feval(df,xx(k));end dx = -fx/dfdx; xx(k+1) = xx(k)+dx; fx = feval(f,xx(k + 1)); a= xx; if abs(dx) < z break; end end l=length(a); fprintf('The approx. Root is %dnn',x); fprintf('Iteration Required is %dn',k) end Now calculating the roots of given polynomials a)- exp(-x)-sin(x) assuming interval (0,1) & Max_Iteration=50 >> f=inline('exp(-x)-sin(x)'); %matlab command to define function >> df=inline('-exp(-x)-cos(x)'); %derivative of f 1)- Bisection method: >> bisct(f,0,1,1e-6,50) The Interval in which root lie is 5.885315e-001 5.885334e-001 Iteration Required is 20 The approx. error is 9.536743e-007 2)- Regula Falsi: >> rfalsi(f,0,1,1e-6,50) The Interval in which root lie is 0 5.885327e-001 Iteration Required is 50 The approx. error is 5.885327e-001 3)- Modified Regula Falsi: >> mrfalsi(f,0,1.0,1e-6,50) The Interval in which root lie is 5.885315e-001 5.885342e-001 Iteration Required is 23 The approx. error is 3.976230e-006 4)- Newton Raphson Method: >> newtonrap(f,df,.2,1e-6,50) The approx. Root is 5.885327e-001 Iteration Required is 4
  • 9. b)- x- exp(-(x^2)) assuming interval (0,1) & Max_Iteration=50 >> f=inline('x-exp(-(x^2))'); %matlab command to define function >> df=inline('1+2*x*exp(-(x^2))'); %derivative of f 1)- Bisection method: >> bisct(f,0,1,1e-6,50) The Interval in which root lie is 6.529179e-001 6.529198e-001 Iteration Required is 20 The approx. error is 9.536743e-007 2)- Regula Falsi: >> rfalsi(f,0,1.0,1e-6,50) The Interval in which root lie is 6.529186e-001 6.534421e-001 Iteration Required is 50 The approx. error is 5.234929e-004 3)- Modified Regula Falsi: >> mrfalsi(f,0,1.0,1e-6,50) The Interval in which root lie is 6.529059e-001 6.529198e-001 Iteration Required is 25 The approx. error is 2.490377e-005 4)- Newton Raphson Method: >> newtonrap(f,df,.5,1e-6,50) The approx. Root is 6.529186e-001 Iteration Required is 4 c)- (x^3)-x-2 assuming interval (-1,2) & Max_Iteration=50 >> f=inline('(x^3)-x-2') %matlab command to define function >> df=inline('3*(x^2)-1'); %derivative of f 1)- Bisection method: >> bisct(f,-1,2,1e-6,50) The Interval in which root lie is 1.521379e+000 1.521382e+000 Iteration Required is 22 The approx. error is 2.861023e-006 2)- Regula Falsi: >> rfalsi(f,-1,2,1e-6,50) The Interval in which root lie is 1.521380e+000 2 Iteration Required is 50 The approx. error is 4.786203e-001
  • 10. 3)- Modified Regula Falsi: >> mrfalsi(f,-1,2,1e-6,50) The Interval in which root lie is 1.521356e+000 1.521386e+000 Iteration Required is 28 The approx. error is 6.021365e-005 4)- Newton Raphson Method: >> newtonrap(f,df,1,1e-6,50) The approx. Root is 1.521380e+000 Iteration Required is 6 Ques3: For finding the the smallest positive guess for which Newton method diverges, we can use Newton Raphson method check for various guess as the root start diverging we can say that that is our required positive guess. Assuming z-1e-006 % Tolerance parameter >> f=inline('atan(x)') f= Inline function: f(x) = atan(x) >> df=inline('1/(1+x^2)') df = Inline function: df(x) = 1/(1+x^2) >> newtonrap(f,df,1,1e-6,1000) The approx. Root is 0 Iteration Required is 5 >> newtonrap(f,df,1.1,1e-6,1000) The approx. Root is -1.803121e-019 Iteration Required is 5
  • 11. >> newtonrap(f,df,1.2,1e-6,1000) The approx. Root is 0 Iteration Required is 6 >> newtonrap(f,df,1.3,1e-6,1000) The approx. Root is 0 Iteration Required is 7 >> newtonrap(f,df,1.38,1e-6,1000) The approx. Root is 0 Iteration Required is 9 >> newtonrap(f,df,1.39,1e-6,1000) The approx. Root is 0 Iteration Required is 11 >> newtonrap(f,df,1.4,1e-6,1000) Warning: Divide by zero. > In newtonrap at 8 Warning: Divide by zero. > In newtonrap at 8 The approx. Root is NaN Iteration Required is 1000 From the above data we get Since at 1.4 there is divide by zero error so beyond 1.4 function (‘atanx’) may diverge. Smallest positive guess will be 1.4.