0% found this document useful (0 votes)
4 views10 pages

Complete Numerical Methods Report

The document provides an overview of various numerical methods for finding roots of functions and performing integration, including the Bisection Method, Newton-Raphson Method, Simpson's Rule, Trapezoidal Rule, and Secant Method. Each method is explained with theoretical foundations, step-by-step iterations, and MATLAB code examples for practical implementation. The document emphasizes the importance of these techniques in numerical analysis and their applications in solving mathematical problems.

Uploaded by

umbutt78601
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

Complete Numerical Methods Report

The document provides an overview of various numerical methods for finding roots of functions and performing integration, including the Bisection Method, Newton-Raphson Method, Simpson's Rule, Trapezoidal Rule, and Secant Method. Each method is explained with theoretical foundations, step-by-step iterations, and MATLAB code examples for practical implementation. The document emphasizes the importance of these techniques in numerical analysis and their applications in solving mathematical problems.

Uploaded by

umbutt78601
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Table of Contents

Bisection Method........................................................................................................................................................................................................ 2
Newton-Raphson Method........................................................................................................................................................................................ 4
Simpson's Rule............................................................................................................................................................................................................. 5
Trapezoidal Rule......................................................................................................................................................................................................... 7
Secant Method.............................................................................................................................................................................................................. 8

Page 1
Bisection Method
Theory
The Bisection Method is a fundamental numerical technique used to find roots of continuous functions.
It is based on the Intermediate Value Theorem, which states that if a continuous function f(x) changes sign over an
interval [a, b],
then there exists at least one root c in that interval such that f(c) = 0.
The method involves:
- Repeatedly halving the interval [a, b],
- Evaluating the function at the midpoint,
- Deciding which subinterval contains the root based on the sign of the function,
- Narrowing the interval until a satisfactory approximation of the root is found.
Bisection Formula:
c = (a + b)/2
If f(a) * f(c) < 0, the root lies in [a, c]; otherwise, it lies in [c, b].
Process is repeated until either the interval is sufficiently small (tolerance ε) or a fixed number of iterations is
reached.

Theoretical (Hand-Solved Example)


Find the root of the function:

f(x) = x^3 - x - 2

in the interval [1, 2], using 4 iterations of the Bisection Method.

Step-by-Step Iterations:

f(1) = 1^3 - 1 - 2 = -2
f(2) = 2^3 - 2 - 2 = 4

Since f(1) * f(2) < 0, a root lies between 1 and 2.

Iteration a b c = (a+b)/2 f(c) Interval Chosen

1 1.0 2.0 1.5 -0.125 [1.5, 2.0]

2 1.5 2.0 1.75 1.609 [1.5, 1.75]

3 1.5 1.75 1.625 0.666 [1.5, 1.625]

4 1.5 1.625 1.5625 0.252 [1.5, 1.5625]

Approximate root after 4 iterations: 1.5625

Page 2
MATLAB
clc
disp('Finding Root Using BISECTION METHOD')
f=input('Enter your function: ');
a=input('Enter lower interval limit: ');
b=input('Enter upper interval limit: ');
n=input('Enter the number of iterations: ');
e=input('Enter tolerance: ');
if f(a)*f(b)<0
for i= 1:n
c=(a+b)/2;
fprintf('Iteration %d = %f\n',i,c)
if abs(c-b)<e || abs(c-a)<e
break
end
if f(a)*f(c)<0
b=c;
elseif f(b)*f(c)<0
a=c;
end
end
else
disp('No root between the guessed values. Try other values')
end

Input and Output (Using the Example Function):


Enter your function: @(x) x^3 - x - 2
Enter lower interval limit: 1
Enter upper interval limit: 2
Enter the number of iterations: 4
Enter tolerance: 0.0001

Finding Root Using BISECTION METHOD


Iteration 1 = 1.500000
Iteration 2 = 1.750000
Iteration 3 = 1.625000
Iteration 4 = 1.562500

Page 3
Newton-Raphson Method
Theory
A powerful iterative technique for finding roots using derivatives.
Formula:
x_{n+1} = x_n - f(x_n)/f'(x_n)
Steps:
- Start with an initial guess x0
- Use formula to compute next x
- Repeat until desired accuracy or number of iterations is achieved.

Theoretical (Hand-Solved Example)


Find the root of the function:

f(x) = x^3 - x - 2

using the Newton-Raphson Method with initial guess x0 = 1.5 and 4 iterations.

Step-by-Step Iterations:

f(x) = x^3 - x - 2
f'(x) = 3x^2 - 1

Iteration x_n f(x_n) f'(x_n) x_(n+1)

1 1.5 -0.125 5.75 1.5217

2 1.5217 0.0021 5.9496 1.5214

3 1.5214 0.0 5.9485 1.5214

4 1.5214 0.0 5.9485 1.5214

Approximate root after 4 iterations: 1.5214

MATLAB
clc
disp('Finding Root Using NEWTON-RAPHSON METHOD')
f = input('Enter your function: ');
df = input('Enter derivative of the function: ');
x0 = input('Enter initial guess: ');
n = input('Enter the number of iterations: ');
e = input('Enter tolerance: ');

for i = 1:n
fx = f(x0);

Page 4
dfx = df(x0);
x1 = x0 - fx/dfx;
fprintf('Iteration %d = %f\n', i, x1)
if abs(x1 - x0) < e
break
end
x0 = x1;
end

Input and Output (Using the Example Function):


Enter your function: @(x) x^3 - x - 2
Enter derivative of the function: @(x) 3*x^2 - 1
Enter initial guess: 1.5
Enter the number of iterations: 4
Enter tolerance: 0.0001

Finding Root Using NEWTON-RAPHSON METHOD


Iteration 1 = 1.521739
Iteration 2 = 1.521379
Iteration 3 = 1.521379
Iteration 4 = 1.521379

Simpson's Rule
Theory
A numerical integration technique that approximates the integral of a function by fitting a second-degree
polynomial (parabola) through three consecutive points.
Formula:
I ≈ (h/3) * [f(a) + 4*f((a+b)/2) + f(b)]
Steps:
- Divide the interval [a, b] into even number of sub-intervals (n must be even)
- Calculate h = (b-a)/n
- Apply the Simpson's formula

Theoretical (Hand-Solved Example)


Evaluate the integral:

∫₀² (x^3 - x - 2) dx

using Simpson’s 1/3 Rule with 4 intervals.

Step-by-Step Iterations:

h = (b-a)/n = (2-0)/4 = 0.5

Page 5
x f(x)

0.0 -2.0

0.5 -2.375

1.0 -2.0

1.5 -0.125

2.0 4.0

Approximate value of integral ≈ (h/3) * [f0 + 4f1 + 2f2 + 4f3 + f4]


= (0.5/3)*( -2 + 4(-2.375) + 2(-2) + 4(-0.125) + 4 ) = -4.6667

MATLAB
clc
disp('Integration Using SIMPSON'S RULE')
f = input('Enter your function: ');
a = input('Enter lower limit: ');
b = input('Enter upper limit: ');
n = input('Enter number of sub-intervals (even number): ');

if mod(n,2)~=0
disp('Number of sub-intervals must be even')
else
h = (b-a)/n;
x = a:h:b;
sum1 = 0;
sum2 = 0;

for i=2:2:n
sum1 = sum1 + f(x(i));
end

for i=3:2:n-1
sum2 = sum2 + f(x(i));
end

I = (h/3)*(f(a) + 4*sum1 + 2*sum2 + f(b));


fprintf('Approximate value of integral: %f\n',I)
end

Page 6
Input and Output (Using the Example Function):
Enter your function: @(x) x^3
Enter lower limit: 1
Enter upper limit: 2
Enter number of sub-intervals (even number): 2
Integration Using SIMPSON'S RULE
Approximate value of integral: 3.875000

Trapezoidal Rule
Theory
A numerical integration method that approximates the area under a curve by dividing it into trapezoids.
Formula:
I ≈ (h/2) * [f(a) + 2*Σf(x_i) + f(b)]
Steps:
- Divide the interval [a, b] into n sub-intervals
- Calculate h = (b-a)/n
- Apply the trapezoidal formula

Theoretical (Hand-Solved Example)


Evaluate the integral:

∫₀² (x^3 - x - 2) dx

using Trapezoidal Rule with 4 intervals.

Step-by-Step Iterations:

h = (b-a)/n = (2-0)/4 = 0.5

x f(x)

0.0 -2.0

0.5 -2.375

1.0 -2.0

1.5 -0.125

2.0 4.0

Approximate value of integral ≈ (h/2) * [f0 + 2(f1+f2+f3) + f4]


= (0.5/2)*( -2 + 2(-2.375-2-0.125) + 4 )
= -4.75

Page 7
MATLAB
clc
disp('Integration Using TRAPEZOIDAL RULE')
f = input('Enter your function: ');
a = input('Enter lower limit: ');
b = input('Enter upper limit: ');
n = input('Enter number of sub-intervals: ');

h = (b-a)/n;
x = a:h:b;
sum = 0;

for i=2:n
sum = sum + f(x(i));
end

I = (h/2)*(f(a) + 2*sum + f(b));


fprintf('Approximate value of integral: %f\n',I)

Input and Output (Using the Example Function):


Enter your function: @(x) x^3
Enter lower limit: 1
Enter upper limit: 2
Enter number of sub-intervals: 2

Integration Using TRAPEZOIDAL RULE


Approximate value of integral: 3.875000

Secant Method
Theory
An iterative technique to find the root of a function using two initial approximations without requiring the
derivative.

Formula:
x_{n+1} = x_n - f(x_n)*(x_n - x_{n-1})/(f(x_n) - f(x_{n-1}))

Steps:
- Start with two initial guesses x0 and x1
- Apply formula iteratively until tolerance or number of iterations is achieved

Page 8
Theoretical (Hand-Solved Example)
Find the root of the function:

f(x) = x^3 - x - 2

using the Secant Method with initial guesses x0 = 1 and x1 = 2, and 4 iterations.

Step-by-Step Iterations:

f(1) = -2
f(2) = 4

Iteration x_(n-1) x_n f(x_(n-1)) f(x_n) x_(n+1)

1 1.0 2.0 -2.0 4.0 1.3333

2 2.0 1.3333 4.0 -0.9629 1.4627

3 1.3333 1.4627 -0.9629 -0.3333 1.5311

4 1.4627 1.5311 -0.3333 0.0714 1.5176

Approximate root after 4 iterations: 1.5176

MATLAB
clc
disp('Finding Root Using SECANT METHOD')
f = input('Enter your function: ');
x0 = input('Enter first initial guess: ');
x1 = input('Enter second initial guess: ');
n = input('Enter number of iterations: ');
e = input('Enter tolerance: ');

for i = 1:n
fx0 = f(x0);
fx1 = f(x1);
x2 = x1 - fx1*(x1 - x0)/(fx1 - fx0);
fprintf('Iteration %d = %f\n', i, x2)
if abs(x2 - x1) < e
break
end
x0 = x1;
x1 = x2;
end

Page 9
Input and Output (Using the Example Function):
Enter your function: @(x) x^3 - x - 2
Enter first initial guess: 1
Enter second initial guess: 2
Enter number of iterations: 4
Enter tolerance: 0.0001

Finding Root Using SECANT METHOD


Iteration 1 = 1.333333
Iteration 2 = 1.462687
Iteration 3 = 1.521380
Iteration 4 = 1.521379

Page 10

You might also like