Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

ES-341: Numerical Analysis: Dr. Mazhar Ali Mehboob Ul Haq (TA)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

ES-341:

Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)

Pseudo Codes

ES-341: Numerical Analysis

Dr. Mazhar Ali


Mehboob ul Haq (TA)

Faculty of Engineering Sciences

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology

30th March 2022

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 1/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)

Pseudo Codes

1 Pseudo Codes

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 2/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
Bisection Method algorithmic procedure for solving f (x) = 0
(TA)
1 Let us consider a function f ∈ C [a, b].
Pseudo Codes
2 such that f (a) · f (b) < 0

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 3/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
Bisection Method algorithmic procedure for solving f (x) = 0
(TA)
1 Let us consider a function f ∈ C [a, b].
Pseudo Codes
2 such that f (a) · f (b) < 0
3 Begin with initial interval a1 = a and b1 = b.

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 3/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
Bisection Method algorithmic procedure for solving f (x) = 0
(TA)
1 Let us consider a function f ∈ C [a, b].
Pseudo Codes
2 such that f (a) · f (b) < 0
3 Begin with initial interval a1 = a and b1 = b.
4 Let us start iteration counter with i = 1

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 3/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
Bisection Method algorithmic procedure for solving f (x) = 0
(TA)
1 Let us consider a function f ∈ C [a, b].
Pseudo Codes
2 such that f (a) · f (b) < 0
3 Begin with initial interval a1 = a and b1 = b.
4 Let us start iteration counter with i = 1
Calculate xi = 12 (ai + bi )

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 3/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
Bisection Method algorithmic procedure for solving f (x) = 0
(TA)
1 Let us consider a function f ∈ C [a, b].
Pseudo Codes
2 such that f (a) · f (b) < 0
3 Begin with initial interval a1 = a and b1 = b.
4 Let us start iteration counter with i = 1
Calculate xi = 12 (ai + bi )
If |f (xi )| < ϵ or |xi − xi−1 | < ϵ, then stop the iteration. If not then
continue ,

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 3/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
Bisection Method algorithmic procedure for solving f (x) = 0
(TA)
1 Let us consider a function f ∈ C [a, b].
Pseudo Codes
2 such that f (a) · f (b) < 0
3 Begin with initial interval a1 = a and b1 = b.
4 Let us start iteration counter with i = 1
Calculate xi = 12 (ai + bi )
If |f (xi )| < ϵ or |xi − xi−1 | < ϵ, then stop the iteration. If not then
continue ,
If f (xi )f (ai ) > 0, then set ai+1 = xi and bi+1 = bi ;

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 3/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
Bisection Method algorithmic procedure for solving f (x) = 0
(TA)
1 Let us consider a function f ∈ C [a, b].
Pseudo Codes
2 such that f (a) · f (b) < 0
3 Begin with initial interval a1 = a and b1 = b.
4 Let us start iteration counter with i = 1
Calculate xi = 12 (ai + bi )
If |f (xi )| < ϵ or |xi − xi−1 | < ϵ, then stop the iteration. If not then
continue ,
If f (xi )f (ai ) > 0, then set ai+1 = xi and bi+1 = bi ; else
If f (xi )f (ai ) < 0, then set ai+1 = ai and bi+1 = xi ;
Set counter i = i + 1; Repeat;
5 Until unless

|xi − xi−1 | ≤ ϵ, OR, |f (xi )| ≤ ϵ

6 End procedure; xi+1 = p such that f (p) ≈ 0.

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 3/7
ES-341:
Numerical Fixed Point Algorithmic procedure for solving f (x) = 0
Analysis

Dr. Mazhar Ali We start with x0 and compute g (x0 ).


Mehboob ul Haq
(TA)

Pseudo Codes

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 4/7
ES-341:
Numerical Fixed Point Algorithmic procedure for solving f (x) = 0
Analysis

Dr. Mazhar Ali We start with x0 and compute g (x0 ). Later we choose the second guess
Mehboob ul Haq
(TA) as x1 = g (x0 )
Pseudo Codes

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 4/7
ES-341:
Numerical Fixed Point Algorithmic procedure for solving f (x) = 0
Analysis

Dr. Mazhar Ali We start with x0 and compute g (x0 ). Later we choose the second guess
Mehboob ul Haq
(TA) as x1 = g (x0 ) continue until we reach the fixed point p such that
Pseudo Codes
p = g (p).

Algorithmic steps
1 Formulate problem f (x) = 0 as fixed point problem x = g (x).

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 4/7
ES-341:
Numerical Fixed Point Algorithmic procedure for solving f (x) = 0
Analysis

Dr. Mazhar Ali We start with x0 and compute g (x0 ). Later we choose the second guess
Mehboob ul Haq
(TA) as x1 = g (x0 ) continue until we reach the fixed point p such that
Pseudo Codes
p = g (p).

Algorithmic steps
1 Formulate problem f (x) = 0 as fixed point problem x = g (x).
2 Check convergence condition i.e., max |g ′ (x)| ≤ k < 1
x∈[a,b]

3 Choose an initial guess x0 .

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 4/7
ES-341:
Numerical Fixed Point Algorithmic procedure for solving f (x) = 0
Analysis

Dr. Mazhar Ali We start with x0 and compute g (x0 ). Later we choose the second guess
Mehboob ul Haq
(TA) as x1 = g (x0 ) continue until we reach the fixed point p such that
Pseudo Codes
p = g (p).

Algorithmic steps
1 Formulate problem f (x) = 0 as fixed point problem x = g (x).
2 Check convergence condition i.e., max |g ′ (x)| ≤ k < 1
x∈[a,b]

3 Choose an initial guess x0 .


4 Let us start iteration counter with i = 0

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 4/7
ES-341:
Numerical Fixed Point Algorithmic procedure for solving f (x) = 0
Analysis

Dr. Mazhar Ali We start with x0 and compute g (x0 ). Later we choose the second guess
Mehboob ul Haq
(TA) as x1 = g (x0 ) continue until we reach the fixed point p such that
Pseudo Codes
p = g (p).

Algorithmic steps
1 Formulate problem f (x) = 0 as fixed point problem x = g (x).
2 Check convergence condition i.e., max |g ′ (x)| ≤ k < 1
x∈[a,b]

3 Choose an initial guess x0 .


4 Let us start iteration counter with i = 0
Keep iterating: xi+1 = g (xi )

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 4/7
ES-341:
Numerical Fixed Point Algorithmic procedure for solving f (x) = 0
Analysis

Dr. Mazhar Ali We start with x0 and compute g (x0 ). Later we choose the second guess
Mehboob ul Haq
(TA) as x1 = g (x0 ) continue until we reach the fixed point p such that
Pseudo Codes
p = g (p).

Algorithmic steps
1 Formulate problem f (x) = 0 as fixed point problem x = g (x).
2 Check convergence condition i.e., max |g ′ (x)| ≤ k < 1
x∈[a,b]

3 Choose an initial guess x0 .


4 Let us start iteration counter with i = 0
Keep iterating: xi+1 = g (xi )
Until following criteria is met

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 4/7
ES-341:
Numerical Fixed Point Algorithmic procedure for solving f (x) = 0
Analysis

Dr. Mazhar Ali We start with x0 and compute g (x0 ). Later we choose the second guess
Mehboob ul Haq
(TA) as x1 = g (x0 ) continue until we reach the fixed point p such that
Pseudo Codes
p = g (p).

Algorithmic steps
1 Formulate problem f (x) = 0 as fixed point problem x = g (x).
2 Check convergence condition i.e., max |g ′ (x)| ≤ k < 1
x∈[a,b]

3 Choose an initial guess x0 .


4 Let us start iteration counter with i = 0
Keep iterating: xi+1 = g (xi )
Until following criteria is met

|xi+1 − xi | ≤ ϵ

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 4/7
ES-341:
Numerical Fixed Point Algorithmic procedure for solving f (x) = 0
Analysis

Dr. Mazhar Ali We start with x0 and compute g (x0 ). Later we choose the second guess
Mehboob ul Haq
(TA) as x1 = g (x0 ) continue until we reach the fixed point p such that
Pseudo Codes
p = g (p).

Algorithmic steps
1 Formulate problem f (x) = 0 as fixed point problem x = g (x).
2 Check convergence condition i.e., max |g ′ (x)| ≤ k < 1
x∈[a,b]

3 Choose an initial guess x0 .


4 Let us start iteration counter with i = 0
Keep iterating: xi+1 = g (xi )
Until following criteria is met

|xi+1 − xi | ≤ ϵ Or |g (xi ) − xi | ≤ ϵ else

Set counter i = i + 1; Repeat;

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 4/7
ES-341:
Numerical Fixed Point Algorithmic procedure for solving f (x) = 0
Analysis

Dr. Mazhar Ali We start with x0 and compute g (x0 ). Later we choose the second guess
Mehboob ul Haq
(TA) as x1 = g (x0 ) continue until we reach the fixed point p such that
Pseudo Codes
p = g (p).

Algorithmic steps
1 Formulate problem f (x) = 0 as fixed point problem x = g (x).
2 Check convergence condition i.e., max |g ′ (x)| ≤ k < 1
x∈[a,b]

3 Choose an initial guess x0 .


4 Let us start iteration counter with i = 0
Keep iterating: xi+1 = g (xi )
Until following criteria is met

|xi+1 − xi | ≤ ϵ Or |g (xi ) − xi | ≤ ϵ else

Set counter i = i + 1; Repeat;


5 End procedure; xi+1 = p such that f (p) ≈ 0.

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 4/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq Newton Method algorithmic steps for solving f (x) = 0
(TA)
1 Let us consider f ∈ C [a, b]
Pseudo Codes
2 Calculate f ′ (x).
3 Choose an initial guess x0 .

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 5/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq Newton Method algorithmic steps for solving f (x) = 0
(TA)
1 Let us consider f ∈ C [a, b]
Pseudo Codes
2 Calculate f ′ (x).
3 Choose an initial guess x0 .
4 Let us start iteration counter with i = 1

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 5/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq Newton Method algorithmic steps for solving f (x) = 0
(TA)
1 Let us consider f ∈ C [a, b]
Pseudo Codes
2 Calculate f ′ (x).
3 Choose an initial guess x0 .
4 Let us start iteration counter with i = 1
Keep iterating:
f (xi−1 )
xi = xi−1 −
f ′ (xi−1 )

Until following criteria is met

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 5/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq Newton Method algorithmic steps for solving f (x) = 0
(TA)
1 Let us consider f ∈ C [a, b]
Pseudo Codes
2 Calculate f ′ (x).
3 Choose an initial guess x0 .
4 Let us start iteration counter with i = 1
Keep iterating:
f (xi−1 )
xi = xi−1 −
f ′ (xi−1 )

Until following criteria is met

|xi − xi−1 | ≤ ϵ

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 5/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq Newton Method algorithmic steps for solving f (x) = 0
(TA)
1 Let us consider f ∈ C [a, b]
Pseudo Codes
2 Calculate f ′ (x).
3 Choose an initial guess x0 .
4 Let us start iteration counter with i = 1
Keep iterating:
f (xi−1 )
xi = xi−1 −
f ′ (xi−1 )

Until following criteria is met

|xi − xi−1 | ≤ ϵ OR |f (xi )| ≤ ϵ else

Set counter i = i + 1; Repeat;


5 End procedure; xi = p such that f (p) = 0 .

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 5/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq Secant Method algorithmic steps for solving f (x) = 0
(TA)
1 To solve the problem f (x) = 0 using Secant method.
Pseudo Codes
2 Choose two initial approximations x0 and x1 . .

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 6/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq Secant Method algorithmic steps for solving f (x) = 0
(TA)
1 To solve the problem f (x) = 0 using Secant method.
Pseudo Codes
2 Choose two initial approximations x0 and x1 . .Let us start iteration
counter with i = 2

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 6/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq Secant Method algorithmic steps for solving f (x) = 0
(TA)
1 To solve the problem f (x) = 0 using Secant method.
Pseudo Codes
2 Choose two initial approximations x0 and x1 . .Let us start iteration
counter with i = 2
Keep iterating:
f (xi−1 )(xi−2 − xi−1 )
xi = xi−1 −
f (xi−2 ) − f (xi−1 )

Until following criteria is met

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 6/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq Secant Method algorithmic steps for solving f (x) = 0
(TA)
1 To solve the problem f (x) = 0 using Secant method.
Pseudo Codes
2 Choose two initial approximations x0 and x1 . .Let us start iteration
counter with i = 2
Keep iterating:
f (xi−1 )(xi−2 − xi−1 )
xi = xi−1 −
f (xi−2 ) − f (xi−1 )

Until following criteria is met

|xi − xi−1 | ≤ ϵ

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 6/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq Secant Method algorithmic steps for solving f (x) = 0
(TA)
1 To solve the problem f (x) = 0 using Secant method.
Pseudo Codes
2 Choose two initial approximations x0 and x1 . .Let us start iteration
counter with i = 2
Keep iterating:
f (xi−1 )(xi−2 − xi−1 )
xi = xi−1 −
f (xi−2 ) − f (xi−1 )

Until following criteria is met

|xi − xi−1 | ≤ ϵ Or |f (xi )| ≤ ϵ else

Set counter i = i + 1; Repeat;


3 End procedure; xi = p such that f (p) = 0 .

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 6/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq Modified Newton algorithmic steps for solving f (x) = 0
(TA)

Pseudo Codes
1 Let us consider f ∈ C 2 [a, b],
2 Calculate f ′ ∈ C [a, b] and f ′′ ∈ C [a, b].
3 Consider an initial guess x0
Start iteration i = 1

f (xi−1 )f ′ (pi−1 )
xi = xi−1 −
(f ′ (xi−1 ))2 − f (xi−1 )f ′′ (xi−1 )

Until following criteria is met

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 7/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq Modified Newton algorithmic steps for solving f (x) = 0
(TA)

Pseudo Codes
1 Let us consider f ∈ C 2 [a, b],
2 Calculate f ′ ∈ C [a, b] and f ′′ ∈ C [a, b].
3 Consider an initial guess x0
Start iteration i = 1

f (xi−1 )f ′ (pi−1 )
xi = xi−1 −
(f ′ (xi−1 ))2 − f (xi−1 )f ′′ (xi−1 )

Until following criteria is met

|xi − xi−1 | ≤ ϵ

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 7/7
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq Modified Newton algorithmic steps for solving f (x) = 0
(TA)

Pseudo Codes
1 Let us consider f ∈ C 2 [a, b],
2 Calculate f ′ ∈ C [a, b] and f ′′ ∈ C [a, b].
3 Consider an initial guess x0
Start iteration i = 1

f (xi−1 )f ′ (pi−1 )
xi = xi−1 −
(f ′ (xi−1 ))2 − f (xi−1 )f ′′ (xi−1 )

Until following criteria is met

|xi − xi−1 | ≤ ϵ OR |f (xi )| ≤ ϵ else

Set counter i = i + 1; Repeat;


4 End procedure; xi = p such that f (p) ≈ 0.

Dr. Mazhar Ali Mehboob ul Haq (TA) (GIKI) ES-341: Numerical Analysis 30th March 2022 7/7

You might also like