Xaliss Jamal Omer - Numerical

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

Numerical Analysis and

Probability

Student Name: Xaliss Jamal Omer

Class: 2nd Stage – Group/B

Course Title: Numerical Analysis and Probability

Department: Software and Informatics

College of Engineering

Salahaddin University-Erbil

Academic Year 2019-2020

1
Q1/ Use the Bisection method to find the root of x3 -0.165x2
+3.993*10-4 =0 given the initial value of xl = 0.00 xu= 0.11
with 10 iterations .
Solution:
let us assume xl(a) = 0.00 , xu(b)=0.11
check if the function changes sign between xl and xu :

f(a) = f(0) = (0)3- 0.165(0)2 + 3.993 * 10-4 = 3.993⨯10-4 >0


f(b) = f(0.11) = (0.11)3- 0.165(0.11)2 + 3.993 ⨯ 10-4 = -2.662⨯10-4<0

The root lies in the interval [0.00,0.11]

Let (t) be the midpoint of the interval

t=(0.00+0.11)/2 = 0.055

t=0.055

f(t)= (0.055)3 - 0.165(0.055)2 +3.993*10-4 = 6.655*10-5

f(t) is positive , so (a) is replaced with t=0.055 for the next


iteration

the iteration for the given functions are:

2
n a F(a) b F(b) c F(c)
1 0.00 3.993⨯10 -4
0.11 -2.662⨯10 -4
0.055 6.655*10-5
2 0.055 6.655*10-5 0.11 -2.662⨯10-4 0.0825 -1.622*10-4
3 0.055 6.655*10-5 0.0825 1.622*10-4 0.0687 -5.563*10-5
4 0.055 6.655*10-5 0.06875 -5.563*10-5 0.0618 4.484*10-6
5 0.0618 4.484*10-6 0.06875 -5.563*10-5 0.0653 -2.59*10-5
6 0.0618 4.484*10-6 0.06531 -2.59*10-5 0.0635 -1.07*10-5
7 0.0618 4.484*10-6 0.06359 -1.07*10-5 0.0627 -3.13*10-6
8 0.0618 4.484*10-6 0.06273 -3.13*10-6 0.0623 6.915*10-7
9 0.0623 6.915*10-7 0.06273 -3.13*10-6 0.0625 -1.22*10-6
10 0.0623 6.915*10-7 0.06251 -1.22*10-6 0.0624 -2.66*10-7
Q2/What is the advantage and disadvantage of Bisection method?

Solution:

Advantages:

 Always Convergent.

 Easy to Understand.

 It is Fault Free 

Disadvantages:

 Can’t Detect Multiple Roots.

 Rate of Convergence is Slow.

 Requires a Lot of Effort.

3
Q3/ Write the pseudo-code of Bisection algorithm.

Solution:

1. Start

2. Define function f(x)

3. Input

a. Lower and Upper guesses x0 and x1

b. tolerable error e

4. If f(x0) * f(x1) > 0

print "Incorrect "

goto 3

End If

5. Do

x2 = (x0+x1) / 2

If f(x0) * f(x2) < 0

x1 = x2

Else

x0 = x2

End If

while abs(f(x2) > e

4
6. Print root as x2

7. Stop

Q4/Use the Newton–Raphson method to find the root of f (x) = x3 −x2


− 2, given the initial value of x0 = 1 with iterations until ε <0.2.

Solution:

f ( Xn)
Xn+1 = xn - f '( Xn)

Derivation of the function is

3x2 -2x

F(x0)=(1)3 – (1)2 – 2 = -2

F’(x0)=3(1)2 – 2(1)=1

−2
X1 = 1 - 1 = 3

F(x1)=(3)3 – (3)2 – 2 = 16

F’(x1)=3(3)2 – 2(3)= 21

………
16
X2 = 3 - 21 = 2.23809

5
F(x2)=(2.2381)3 – (2.2381)2 – 2 =4.2017

F’(x2)=3(2.2381)2 – 2(2.281)= 10.465

………
4.2017
X3 = 2.2381 - 10.465 = 1.8365

F(x3)=(1.8365)3 – (1.8365)2 – 2 = 0.8212

F’(x3)=3(1.8365)2 – 2(1.8365)= 6.4451


0.8212
X4 = 1.8365 - 6.4451 = 1.7091

F(x4)=( 1.7091)3 – (1.7091)2 – 2 = 0.0712

F’(x4)=3(1.7091)2 – 2(1.7091)= 5.3448

…………
0.0712
X5 = 1.7091- 5.3448 = 1.6957

F(x5)=( 1.6957)3 – (1.6957)2 – 2 = 4.1472

F’(x5)=3(1.6957)2 – 2(1.6957)= 5.2347

………….
4.1472
X6 = 1.6957- 5.2347 = 0.9034

………………………………………

6
Q5/What is the advantage and disadvantage of Newton's method?

Solution:

Advantages:

 In general, Netwon’s method has quadratic convergence: the error is


squared at each iteration (the number of accurate digits doubles).

 Very simple.

Disadvantages:

 Newton's method will fail in cases where the derivative is zero. When
the derivative is close to zero, the tangent line is nearly horizontal and
hence may overshoot the desired root (numerical difficulties).
Solution: Try another initial point.

 Newton's method requires calculating the derivative. In many cases,


the function is given by a complex formula and an analytical
expression for the derivative may not be easy to calculate. Solution:
We can use Secant method, which approximates the derivative by
using the slope of a line through two points on the function.

Q6/Write the pseudo-code of Newton algorithm.

Solution:

1. Start

2. Define function as f(x)

3. Define derivative of function as g(x)


7
4. Input:

a. Initial guess x0

b. Tolerable Error e

c. Maximum Iteration N

5. Initialize iteration counter step = 1

6. Do

If g(x0) = 0

Print "Mathematical Error"

Stop

End If

x1 = x0 - f(x0) / g(x0)

x0 = x1

step = step + 1

If step > N

Print "Not Convergent"

Stop

End If

While abs f(x1) > e

7. Print root as x1

8. Stop

8
Q7/Evaluate the integral of the following tabular data with

X -2 0 2 4 6 8 10

f(x) 35 5 -10 2 5 3 20

Solution : (a) trapezoidal rule and.

Xi+1
h
∫ f ( x ) dx ≈ (f(xi)+f(xi+1))
Xi
2

X6

∫ f ( x ) dx m=6 h=(x6- x0)/m


X0

h=(10-(-2))/6=2

∫ f ( x ) dx ≈ A 1+ A 2+ A 3+ A 4+ A 5+ A 6
a

h h h h h
= (f(x0)+f(x1)) + (f(x1)+f(x2)) + (f(x2)+f(x3)) + (f(x3)+f(x4)) +
2 2 2 2 2

h
(f(x4)+f(x5)) + (f(x5)+f(x6))
2
= 1(35+5)+ 1(5+(-10))+ 1((-10)+2)+ 1(2+5)+ 1(5+3)+ 1(3+20)
= 40-5-8+7+8+23 = 65

b m−1

∫ f ( x ) dx ≈ ∑ h2 (f ( x i)+ f ( x i +1))
a i=0

h
= [f(x0)+f(xm)+2{ f(x1)+ f(x2)+ f(x3)+ f(x4)+ f(x5(m-1))}]
2
2
= [35+20+2{ 5+ (-10)+ 2+ 5+ 3}] = 65
2

9
(b) Simpson’s 1/3 rules.

Xi+2
h
f ( x ) dx ≈

Xi
3 (yi+ 4yi+1 + yi+2)

X6
h h h
∫ f ( x ) dx ≈ 3
(y0+ 4y1 + y2) + (y2+ 4y3 + y4) + (y4+ 4y5 + y6)
3 3
X0

2 2 2
= 3 (35+ 4(5) + (-10)) + 3 ((-10)+ 4(2) + 5) + 3 (5+ 4(3) + 20)

74
= 30+2+ 3 = 56.666

X6
h
∫ f ( x ) dx ≈ 3
[(y0+ym) + 4(y1+ y3+ y5) + 2(y2+ y4)]
X0

2
= 3 [(35+20) + 4(5+ 2+ 3) + 2(-10+ 5+ 5)] = 56.66

10
Q8/Use a central difference, and the value of h shown, to approximate
the derivative of cos(x) at x = π/3.

(a) h = 0.1 (b) h = 0.01 (c) h = 0.001 (d) h = 0.0001


Work to 8 decimal places throughout.

Solution:

(a) f ‘(0.1) = (cos (xi+h) – cos (xi-h)) / 2(h)

f ‘(0.1) = (cos (60+0.1) – cos (60-0.1)) / 2(0.1)

f ‘(0.1) = (0.41104381 – 0.58396036) / 0.2

f ‘(0.1) = -0.86458275

……………………………………………………….

(b) f’(0.01) = (cos (xi+h) – cos (xi-h)) / 2(h)

f’(0.01) = (cos (60+0.01) – cos (60-0.01)) / 2(0.01)

f’(0.01) = (0.49131489 0.50863511) / 0.02

f’(0.01) = -86601097

11
………………………………………………………..

(c) f’(0.001) = (cos (xi+h) – cos (xi-h)) / 2(h)

f’(0.01) = (cos (60+0.001) – cos (60-0.001)) / 2(0.001)

f’(0.01) = (0.49913372-0.5008578) / 0.002

f’(0.01) = -0.86602526

……………………………………………………………….

(d) f’(0.0001) = (cos (xi+h) – cos (xi-h)) / 2(h)

f’(0.0001) = (cos (60+0.0001) – cos (60-0.0001)) / 2(0.0001)

f’(0.0001) = (0.49991339-0.50008660) / 0.0002

f’(0.0001) = -0.86602540

Q9/Find the first and second derivatives at each point in the following
table using the forward-, backward-, and central-difference methods.

X -2 0 2 4 6 8 10

f(x) 35 5 -10 2 5 3 20

Solution:

12
h=(x6- x0)/m

h=(10-(-2))/6=2
forward- difference
y i+1− y i
yi’≈ h
y i+2−2 y i+1+ yi
yi” ≈ h2
backward- difference
y i− y i−1
yi’≈ h
y i−2 y i−1+ yi−2
yi” ≈ h2
central-difference
forward- backward- central-
difference difference difference

i x y y’ y” y’ y” y’ y”
0 -2 35 -15 3.75 Void Void Void Void
1 0 5 -7.5 6.75 -15 Void -11.25 3.75
2 2 -10 6 -2.25 -7.5 3.75 -1.75 6.75
3 4 2 1.5 -1.25 6 -3.25 3.75 -2.25
4 6 5 -1 -6.75 1.5 -2.25 0.25 -1.25
5 8 3 8.5 Void -1 -1.25 3.75 0.25
6 10 20 void void 8.5 4.75 void void
y i+1− y i−1
yi’≈ 2h

13
y i+1−2 y i+ yi −1
yi” ≈ h2

Q10/ Find ∫ x sin dx using the Simpson’s 3/8 method with nine
0

subintervals.

Solution: In this problem , m= 9 , x0 = 0, and xm = 3 . The width of each


3−0
subinterval is h = 9 = 0.333333 with nine subintervals , there are 10

points on y =f(x) = x sinx , and their values are shown in the following
table :

i 0 1 2 3 4 5 6 7 8 9
xi 0 0.3333 0.6667 1.000 1.3333 1.6667 2.0000 2.3333 2.6667 3.0000
yi 0 0.1090 0.4122 0.841 1.2959 1.6590 1.8186 1.6872 1.2194 0.4234
4

9
3h
∫ f ( x ) dx ≈ 8
[(y0+y9) + 2(y3+ y6) + 3(y1+ y2+ y4 +y5+ y7+ y8)]
0

= 3.1112

Q11/Given y = x sin x, find y’ and y’’ at the points along 0 ≤ x ≤ 2 whose


subintervals have an equal width given by h = 0.3333 using the
forward, backward and central-difference methods.

Solution:

14
m = (2-0) / 0.3333=6

At i = 0 , y’0 and y’’0 can be evaluated using the forward difference rules
using Equation

y 1− y 0 0.1090−0
y’0 = h
=
0.3333
=0.3270

forward- backward- central-


difference difference difference

i x y y’ y” y’ y” y’ y”
0 0 0 0.3270 1.7481 Void Void Void Void

1 0.333 0.109 0.9097 1.1342 0.3270 Void 0.6183 1.7481


3 0
2 0.666 0.412 1.2877 0.2277 0.9097 1.7481 1.0987 1.1342
7 2
3 1.000 0.841 1.3636 -0.822 1.2877 1.1342 1.3257 0.2277
0 4
4 1.333 1.295 1.0894 -1.831 1.3636 0.2277 1.2265 -0.8228
3 9
5 1.666 1.659 0.4788 Void 1.0894 -0.8228 0.7841 -1.8319
7 0
6 2.000 1.818 void void 0.4788 -1.8319 void void
0 6

15
y 2−2 y 1+ y 0 0.4122−2 ( 0.1090 ) +0
y’’0 = h∗h
= =1.7481
( 0.3333 )∗(0.3333)

16

You might also like