Numerical Methods Algorithm and C Program

niravbvyas 68 views 22 slides Oct 20, 2024
Slide 1
Slide 1 of 22
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22

About This Presentation

Numerical Methods Algorithms and C Program


Slide Content

Numerical Methods Algorithms & C Program Dr. Nirav Vyas – Associate Professor, Dept. of Science & Humanities, FoET Atmiya University, INDIA

1. Bisection Method 2. Power Method 3. Lagrange’s Interpolation Method

Bisection Method Algorithm & C Program

Bisection Method - Algorithm Start Define function f(x) Choose initial guesses x0 and x1 such that f(x0)f(x1) < Choose pre-specified tolerable error e Calculate new approximated root as x2 = (x0 + x1)/ 2 Calculate f(x0)f(x2) if f(x0)f(x2) < 0 then x0 = x0 and x1 = x2 if f(x0)f(x2) > 0 then x0 = x2 and x1 = x1 if f(x0)f(x2) = 0 then goto (8 ) if |f(x2)| > e then goto (5) otherwise goto (8 ) Display x2 as root . Stop

Bisection Method – C Program Program : Finding real roots of nonlinear equation using Bisection Method Header files User define function for nonlinear equation: x^3 – 9x + 1 = 0

Declaration of variables Input from the user

Checking of the input values Input from the user for tolerable error Setting the output screen format

Start the looping structure until fc gets less then tolerable error Inside loop first find c value using bisection method & function of c Print on screen all values of step, a, b, c and fc

Now to check whether c will replace a or b Increase the step size by 1 Print the root of the equation

Power Method Algorithm & C Program

Power Method - Algorithm 1. Start 2. Read Order of Matrix (n) and Tolerable Error (e) 3. Read Matrix A of Size n x n 4. Read Initial Guess Vector X of Size n x 1 5. Initialize: Lambda_Old = 1 6. Multiply: X_NEW = A * X 7. Replace X by X_NEW 8. Find Largest Element ( Lamda_New ) by Magnitude from X_NEW 9. Normalize or Divide X by Lamda_New 10. Display Lamda_New and X 11. If | Lambda_Old - Lamda_New | > e then set Lambda_Old = Lamda_New and goto step (6) otherwise goto step (12) 12. Stop

Power Method – C Program Program: Write a C program to find Larges Eigen Value and Eigen Vector using Power Method. Header files Universal Constant (maximum size of matrix) Declaration of variables

Title and input from the user Reading Matrix from user (order n x n)

Reading initial Guess Vector from user (order n x 1) Initializing Lambda_old Multiplication

Replacing old eigen vector with new Finding largest numerical value from the vector Normalization – dividing each element of vector with the largest value

Display step, eigen value and eigen vector Checking the accuracy (either repeat the process or stop )

Lagrange’s Interpolation Method Algorithm & C Program

Lagrange’s Interpolation Method - Algorithm 1. Start 2. Read number of data (n ) ( how many pairs of ( x,y ) ) 3. Read data and for 4. Read the value of whose corresponding value of is to be determined. 5. Initialize: = 0 6. Formula for Lagrange’s Interpolation: y= where 7. Display the value of as interpolated value. 8. Stop  

Lagrange’s Interpolation Method – C Program Program: Write a C program to interpolate value of y for the given value of x from the set of data given by the user using Lagrange’s interpolation formula. Header files Declaration of variables

Read number of data ( n) and read data and for Read the value of whose corresponding value of is to be determined  

Implementing Lagrange’s formula Display interpolated value y