NUMERICAL METHODS KIT FOR MATLAB, SCILAB AND OCTAVE USERS
Rohan Verma University of Delhi
ISBN: 978-1-64951-183-6 © Rohan Verma 2020 All rights reserved
Preface I take great pleasure in presenting to the readers this book entitled Engineering, Mathematics and Statistics students. A look at the contents of the book will give the reader a clear idea of the variety of numerical methods discussed and analysed. The book has been written in a concise and lucid style with proper explanation of Mathematics involved in each method. Each method is explained with solved examples, computer programs and their results like a screenshot of the graphic window and console window. The careful organisation of figures, solved examples, codes, graphic window and console window help the students grasp quickly. Despite careful editing, there is zero probability that this book is error-free. If anything looks amiss, please send that part to my email id given below. Email:
[email protected]
Rohan Verma
CONTENTS . Solutions of Algebraic and Transcendental Equations 1.1 Bisection Method 1.2 Newton-Raphson Method 1.3 Regula-Falsi Method 1.4 Secant Method
1 1 4 8 14
2. Interpolation
19
2.1 Finite Difference Operator tion Method
3. Curve Fitting 3.1 Line Fitting 3.2 Parabola Fitting
4. Numerical Differentiation 4.1 Equal Interval 4.2 Unequal Interval
5. Numerical Integration 5.1 Newton-Cotes Formula 5.2 Trapezoidal Rule 5.3 Simpson's 1/3 rule 5.4 Simpson's 3/8 rule 5.5 Monte Carlo method
6. Ordinary Differential Equation 6.1 Classification of differential equations 6.2 Euler Method 6.3 Runge Kutta method
19 20 23 26
28 28 30
33 33 34
35 36 37 39 40 42
45 46 47 61
7. Linear Algebra 7.1 Gaussian Elimination Method 7.2 Gauss-Jordan Elimination Method 7.3 Jacobi Method 7.4 Gauss-Seidel Method
8. Finite Difference Method 8.1 Classification of PDE 8.2 Finite Difference Fundamentals 8.3 2D Laplace's Equation 8.4 1D Heat Equation 8.5 1D Wave Equation
63 67 73 77 81
85 85 87 92 96 100
CHAPTER Solutions of Algebraic and Transcendental Equations is called equation and the values of for which this equation satisfied is called roots of the equation. Algebraic Equation - If is purely polynomial. E.g. containing logarithm, trigonometric, Transcendental Equations - If exponential function, etc. E.g.
Bisection Method The bisection method applies to a continuous function. Let our equation is Here (Figure 1.1) we are going to consider two values of , and and . Clearly, we can see in Figure 1.1 that the root such that must lie somewhere between and .
Figure Take There could be three possibilities. (a) replace
with
(b) 1
replace
with
(c) is the root of equation . We are replacing or with to make a smaller interval for finding the root. In this way, we keep bisecting the interval for finding the root. Eventually, the interval will coincide with the for which . Working rule and (a) Find and such that (b) Find the first approximate root using.
Now calculate between If
and Examine its sign. If
and . 2 approximate root is given by it implies that root lies between . Calculate
required accuracy of root or Find the
th
.
it implies that root lies
nd
root is given by
Example
or
and
. .Then 2 approximate nd
. Repeat the (b) step until the .
approximate real root of the equation
using the Bisection Method. Let and take
First approximate root is
New value of Second approximate root is
New value of Third approximate root is
2
New value of Fourth approximate root is
New value of Fifth approximate root is
, where is the root of In the previous example, we can see that equation . Scilab Code //bisection method clc clear function z=f(x) z=x^3 endfunction n=input("input the interval where you want to find the roots of given equation") a=n(1) b=n(2) c=(a+b)/2 tol=0.00000000001 if f(a)*f(b)tol if f(a)*f(c)tol x1=x0-f(x0)/numderivative(f,x0) disp(x1) x0=x1 end disp("root of equation is "+string(x0)+"")
7
Console Window
Regula-Falsi Method Let our equation is . First, we need to consider a root-finding interval . Such that and or . It is quite obvious ). Here we can that root must lie somewhere between and (see Figure see that it is looking very similar to the Bisection Method till now. But in the Regula Falsi Method instead of the bisecting interval, we draw a line segment joining and see Figure 1.3, this line segment intersects at x-
8
axis at .This is closer to the root of equation is our first approximate root of the equation.
, we can say that
Figure 1.3 Now for
nd
approximate root, we check the sign of
If
replace
with
.
If
replace
with
.
Keep doing this process until
, where
is the root of equation
.
Working rule (a) Let and (b) Find Joining
be the equation to solve. Take
and
such that
. st
approximate root by constructing equation of line segment ) and ) and putting .
Putting
9
(c) Check the sign of
.
replace
with
If
approximate root
nd
replace
If nd
with
approximate root
(c) repeat the third step until convergence reached.
Example 1.3 Find the 7th approximate root of
by Regula Falsi
method. Let
and
,
and st
approximate root
New value of nd
approximate root
New value of
10