Вы находитесь на странице: 1из 16

Numerical Analysis

FINAL EXAMINATION
LECTURER: Prof. SUN Heming

SUBMITTED BY:
IWAN MUHAMMAD SYARIEFUDIN (马伊万)
Student Category : Masters in College of Hydrology and Water Resources
Student No: M2015101
Email : m2015101@hhu.edu.cn

COLLEGE OF HYDROLOGY AND WATER RESOURCES ENGINEERING


HOHAI UNIVERSITY NANJING PR CHINA
2016
1. P 65 no. 15

Use a fixed-point iteration method to determine a solution accurate to within 10-2 for

2 sin x + x = 0 on [1,2]. Use p0 = 1.

Solving ;

Manipulate the equation 2 sin π x + x = 0 as follow :

a. X = g (x) = - -

b. X = arc sin ( ) + 2

n (a) (b)
0 1 1
1 1,634887662 1,833333333
2 1,619134377 1,630869246
3 1,625036752 1,696498005
4 1,622854573 1,677657062
5 1,623665437 1,683240993

 For X = g (x) = - - ;

P5 = 1,623665437 is accurate within 0,01 ( 10-2 )

 For X = arc sin ( ) + 2 ;

P5 = 1,683240993 is accurate within 0,01 ( 10-2 )


2. P 119 no. 3(b) (only degree 3)

Use appropriate Lagrange interpolating polynomials of degrees one, two and three to
approximate each of the following :

f( ) if f (-0,75) = - 0,07181250, f (-0,5) = -0,02475000, f (-0,25) = 0,33493750,


f (0) = 1,10100000

Solve :

x f (x )
X0 -0,75 -0,07181250
X1 -0,5 -0,02475000
X2 -0,25 0,33493750
X3 0 1,10100000
( ) ( ) (( ) –( )) (( ) –( ))
P1 (x) = * f(x1) + * f(x2) = * (-0,024750) + * (0,33493750)
( ) ( ) (( ) ( )) (( ) ( ))

= 0,21504167

( )( ) ( )( ) ( )( )
P2 (x) = ( )( )
* f(x0) + ( )( )
* f(x1) + ( )( )
* f(x2)

(( ) –( ))(( ) –( )) (( ) –( ))(( ) –( ))
= * (-0,0718125) + * (-0,024750)
(( ) ( ))(( ) –( )) (( ) ( ))(( ) –( ))

(( )–( ))(( ) –( ))
+ (( ) ( ))(( ) –( ))
* (0,33493750)

= 0,16988889
( )( )( ) ( )( )( ) ( )( )( )
P3 (x) = ( )( )( )
* f(x0) + ( )( )( )
* f(x1) + ( )( )( )
* f(x2)

( )( )( )
+ ( )( )( )
* f(x3)

(( )–( ))(( )–( ))(( ) )


= * (-0,0718125)
(( ) ( ))(( )–( ))(( ) )

(( ) –( ))(( ) –( ))(( )– )
+ * (-0,024750)
(( ) ( ))(( )–( ))(( ) )

(( )–( ))(( ) –( ))(( )– )


+ * (0,33493750)
(( ) ( ))(( )–( ))(( ) )

(( )–( ))(( ) –( ))(( )–( ))


+ * (1,10100000)
( ( ))( –( ))( ( ))

= 0,17451852

So, solving for f ( ) (degree 3) is 0,17451852


3. P 203 no. 2(a)

Use the Composite Simpson’s rule to approximate the integrals in Exercise 1

∫ , n =4

To solve the problem, I’m using MATLAB program. And this is the source code:

clear;
clc;

f= @(x) x.*(log(x));
a=1;
b=2;
n=4;

if ( rem(n,2) ~= 0 )
disp
return
end

h = (b-a)/n;
x = linspace ( a, b, n+1 );
for i = 1:n+1
fx(i) = feval ( f, x(i) );
end
w = [ 1 zeros(1,n-1) 1 ];
w(2:2:n) = 4*ones(1,n/2);
w(3:2:n-1) = 2*ones(1,n/2-1);

if ( nargout == 1 )
y = (h/3) * sum ( w .* fx );
else
disp ( (h/3) * sum ( w .* fx ) );
end

And the answer is 0.6363


4. P 322 no. 2(c)

Use the Runge-Kutta for System Algorithm to approximate the solutions of the following higher-
order differential equations, and compare the result to the actual solutions.

y’” + 2y” - y’ - 2y = et, 0 t 3 , y(0) = 1 , y’(0) = 2, y”(0) = 0, with h = 0,2 ;

actual solution y(t) = et + et + e-2t + tet.

Solving :

u1(t) = y(t) ; u2(t) = y’(t) ; u3(t) = y”(t)

u1’(t) = y’(t) = u2(t)

u2’(t) = y”(t) = u3(t)

u3’(t) = y”’(t) = et + 2y(t) + y’(t) - 2y”(t)

with initial conditions : u1(0) = 1 ; u2(0) = 2 ; u3(0) = 0

The initial conditions give : w1,0 = 1 ; w2,0 = 2 and w2,0 = 0

k1,1 = h f 1(t0 , w1,0 , w2,0 , w3,0 ) = h w3,0 = 0.400000

k1,2 = h f 1(t0 , w1,0 , w2,0 , w3,0 ) = h w2,0 = 0

k1,3 = h f 3(t0 , w1,0 , w2,0 , w3,0) = h [ et0 + 2*w1,0 + w2,0 - 2*w3,0 ] = 1.0000

k2,1 = h [ w3,0 + k1,3 ] = 0.440000

k2,2 = h [ w2,0 + k1,2 ] = 0.10000

k2,3 = h [ et0+0,5h + 2 ( w1,0 + k1,1 ) + ( w2,0 + k1,2 ) - 2(w3,0 + k1,3 ) ] = 0.90103

k3,1 = h [ w3,0 + k2,3 ] = 0.410000

k3,2 = h [ w2,0 + k2,2 ] = 0.090103

k3,3 = h [et0+0,5h + 2 ( w1,0 + k2,1 ) + ( w2,0 + k2,2 ) - 2(w3,0 + k2,3 ) ] = 0.93083

k4,1 = h [ w3,0 + k3,3 ] = 0.41802

k4,2 = h [ w2,0 + k3,2 ] = 0.18617

k4,3 = h [ et0+h + 2 ( w1,0 + k3,1 ) + ( w2,0 + k3,2 ) - 2(w3,0 + k3,3 ) ] = 0.85397


w1,1 = w1,0 + ( k1,1 + 2 k2,1 + 2k3,1 + k4,1 ) = 1.4063

w2,1 = w2,0 + ( k1,2 + 2 k2,2 + 2k3,2 + k4,2 ) = 2.0944

w3,1 = w3,0 + ( k1,3 + 2 k2,3 + 2k3,3 + k4,3 ) = 0.9196

For next k1,i ; k2,i ; k3,i ; k4,i can computed by following :

k1 , i = h f i(tj , w1,j , w2,j , w3,j ), for each i = 1,2,3

k2 , i = h f i [tj + , w1 , j + k1,1 , w2 , j + k1,2 , w3 , j + k1,2 ]

k3 , i = h f i [tj + , w1 , j + k2,1 , w2 , j + k2,2 , w3 , j + k2,2 ]

k4 , i = h f i [tj + h , w1 , j + k3,1 , w2 , j + k3,2 , w3 , j + k3,2 ]

wi , j = w i , j + ( k1 , i + 2 k 2 , i + 2k 3 , i + k 4 , i )
This isthe result

t(i) w1,j y(i) (actual)


0,2 1,406337 1,406374
0,4 1,857092 1,849235
0,6 2,382374 2,361970
0,8 3,013195 2,977624
1,0 3,783771 3,731704
1,2 4,733724 4,664698
1,4 5,910341 5,824547
1,6 7,371049 7,269288
1,8 9,186270 9,070043
2,0 11,442819 11,314529
2,2 14,248011 14,111293
2,4 17,734683 17,594864
2,6 22,067365 21,932090
2,8 27,449891 27,329944
3,0 34,134793 34,045172
5. P 618 no. 3(c)
Use Newton’s method to find a solution to the following nonlinear system in the given
domain. Iterate until ‖ ( ) - ( - )‖ 10-6
x13 + x12x2 - x1x3 + 6 = 0
+ - x3 = 0
2
x2 - 2x1x3 = 4
(0)
Use x = ( -1 , -2, 1)

Solving :
F(x1, x2, x3) = ( f1(x1, x2, x3) , f2(x1, x2, x3) , f3(x1, x2, x3))t
3 2
f1(x1, x2, x3) = x1 + x1 x2 - x1x3 + 6
f2(x1, x2, x3) = + - x3
f3(x1, x2, x3) = x22 - 2x1x3 - 4

The Jacobian matrix J(x) for this system is

3x12 + 2x2x1 - x3 x12 -x1


J(x1, x2, x3) =
ex1 ex2 -1

-2x3 2x2 -2x1

Let x(0) = ( -1 , -2, 1)t . Then F ( x(0 ) = ( 4 , -0.4967853 , 2)t

6 1 1
0,367879441 0,135335283 -1
J ( x(0 ) =

-2 -4 2

Solving the linear system J ( x(0 ) y(0) = - F ( x(0 ) gives :

-1,6821556
y (0) = -0,682156 and x(1) = x(0) + y(0) =
-1,5142772
0,4857228
0,3347072
-0,665293
Thus , at the k step, here the solution :

x1 -1
x(0) x2 -2
x3 1
f1 (x1 , x2 , x3) 4
(0)
F(x ) f2 (x1 , x2 , x3) -0,49678528
f3 (x1 , x2 , x3) 2

6 1 1,00000000

J(x(0)) 0,367879441 0,135335283 -1

-2 -4 2

0,167140196 0,268906567 0,050883185


J-1(x(0)) -0,05666046 -0,627448655 -0,285394099

0,053819283 -0,985990744 -0,019905013


0,167140196 0,268906567 0,050883185 -4 -0,6821556
y(x(0)) -0,05666046 -0,627448655 -0,285394099 x 0,496785276 = 0,4857228
0,053819283 -0,985990744 -0,019905013 -2 -0,6652928
-1 -0,682155632 -1,68215563
x(1) -2 + 0,485722771 = -1,51427723
1 -0,665292788 0,334707212

x1 -1,68215563
x(1) x2 -1,51427723
x3 0,33470721
f1 (x1 , x2 , x3) -2,48174886
F(x(1)) f2 (x1 , x2 , x3) 0,07123256
f3 (x1 , x2 , x3) -0,58090523

13,24873544 2,82964757 1,68215563

J(x(1)) 0,185972655 0,219967113 -1

-0,66941442 -3,028554457 3,364311264

0,074073918 0,473031122 0,103565704


J-1(x(1)) -0,00141591 -1,479125716 -0,43894391

0,01346427 -1,23738816 -0,077292836


0,074073918 0,473031122 0,103565704 2,481748857 0,1818057
y(x(1)) -0,00141591 -1,479125716 -0,43894391 x -0,07123256 = -0,1531368
0,01346427 -1,23738816 -0,077292836 0,580905231 0,0766574
-1,68215563 0,181805695 -1,50034994
x(2) -1,51427723 + -0,153136835 = -1,66741406
0,334707212 0,076657446 0,411364658
x1 -1,50034994
x(2) x2 -1,66741406
x3 0,41136466
f1 (x1 , x2 , x3) -0,513604
(2)
F(x ) f2 (x1 , x2 , x3) 0,00042192
f3 (x1 , x2 , x3) 0,01465154

11,34519431 2,251049933 1,50034994


(2)
J(x ) 0,223052092 0,188734491 -1

-0,82272932 -3,334828127 3,000699873

0,086659498 0,368053736 0,079326215


-1 (2)
J (x ) -0,00480226 -1,104270818 -0,365603288

0,018423229 -1,126318835 -0,051308072


0,086659498 0,368053736 0,079326215 0,513604 0,0445088
y(x(2)) -0,00480226 -1,104270818 -0,365603288 x -0,00042192 = 0,0033561
0,018423229 -1,126318835 -0,051308072 -0,01465154 0,0106892
-1,50034994 0,044508845 -1,45584109
x(3) -1,66741406 + 0,003356107 = -1,66405796
0,411364658 0,010689208 0,422053866

x1 -1,45584109
x(3) x2 -1,66405796
x3 0,42205387
f1 (x1 , x2 , x3) 0,00190068
F(x(3)) f2 (x1 , x2 , x3) 0,00051924
f3 (x1 , x2 , x3) -0,00202439

10,78157389 2,119473283 1,45584109

J(x(3)) 0,233204135 0,189368968 -1

-0,84410773 -3,328115913 2,911682183

0,090803083 0,360253046 0,078325233


-1 (3)
J (x ) -0,00539872 -1,070018672 -0,364792215

0,020153304 -1,118615832 -0,050814557


0,090803083 0,360253046 0,078325233 -0,00190068 -0,0001726
y(x(3)) -0,00539872 -1,070018672 -0,364792215 x -0,00051924 = -0,0001726
0,020153304 -1,118615832 -0,050814557 0,002024394 0,0004397
-1,45584109 -0,000172618 -1,45601371
x(4) -1,66405796 + -0,000172629 = -1,66423059
0,422053866 0,000439653 0,422493519
x1 -1,45601371
x(4) x2 -1,66423059
x3 0,42249352
f1 (x1 , x2 , x3) 0,00031359
(4)
F(x ) f2 (x1 , x2 , x3) 6,6446E-06
f3 (x1 , x2 , x3) -2,3847E-05

10,78371934 2,11997592 1,45601371


(4)
J(x ) 0,233163884 0,18933628 -1

-0,84498704 -3,328461171 2,912027418

0,091074647 0,361388977 0,078564865


-1 (4)
J (x ) -0,00544418 -1,070185201 -0,364783106

0,020204539 -1,118362027 -0,050748187


0,091074647 0,361388977 0,078564865 -0,00031359 -2,856E-05
y(x(4)) -0,00544418 -1,070185201 -0,364783106 x -6,6446E-06 = 1,194E-07
0,020204539 -1,118362027 -0,050748187 2,38467E-05 -1,149E-07
-1,45601371 -2,85597E-05 -1,45604227
x(5) -1,66423059 + 1,19365E-07 = -1,66423047
0,422493519 -1,14913E-07 0,422493404

The results using this iterative procedure are shown in Table below :

k x1 x2 x3
0 -1 -2 1

1 -1,682155632 -1,514277229 0,334707212 0,665292788

2 -1,500349937 -1,667414063 0,411364658 0,076657446

3 -1,455841091 -1,664057957 0,422053866 0,010689208

4 -1,456013709 -1,664230586 0,422493519 0,000439653

5 -1,456042269 -1,664230466 0,422493404 1,14913E-07

X (5) = ( -1,456042269 , -1,664230466 , 0,422493404 ) t


6. P 665 no. 3(b)
Use the Linear Finite Difference Algorithm to approximate the solution to the following
boundary-value problem.

y” = y’ + y ln x , 1 x 2 , y(1) = , y(2) = ln 2 ; use h = 0,05

To solve the problem, I’m using MATLAB program. And this is the source code:

clear;
clc;

a=1.0;
b=2.0;

alpha=-1/2;
beta=log(2);

h=0.05;
N=((b-a)/h)-1;

for i=1:N
x=a+i*h;
A(i,i)=2+h^2*fungQ(x);
end

for i=1:N-1
x=a+i*h;
A(i,i+1)=-1+((h/2)*fungP(x));
end

for i=2:N
x=a+i*h;
A(i,i-1)=-1-((h/2)*fungP(x));
end
A

x=a+h;
b(1,1)=-h^2*fungR(x)+(1+((h/2)*fungP(x)))*alpha;
for i=2:8
x=a+i*h;
b(i,1)=-h^2*fungR(x);
end

xN=a+N*h;
b(N,1)=-h^2*fungR(xN)+(1-((h/2)*fungP(xN)))*beta;
b

for i=1:N
A(i,N+1)=b(i,1);
end
A
for j=1:N-1
if A(j,j)==0
for p=1:N+1
u=A(j,p);
v=A(j+1,p);
A(j+1,p)=u;
A(j,p)=v;
end
end
jj=j+1;
for i=jj:N
m=A(i,j)/A(j,j);
for k=1:(N+1)
A(i,k)=A(i,k)-(m*A(j,k));
end
end
end

x(N,1)=A(N,N+1)/A(N,N);

for i=N-1:-1:1
S=0;
for j=N:-1:i+1
S=S+A(i,j)*x(j,1);
end
x(i,1)=(A(i,N+1)-S)/A(i,i)
end

w=x

and this is the source code for the function of fungP(x), fungQ(x) and fungR(x) :

fungP(x) :

function y = fungP(x)
y = -4/x;

fungQ(x) :

function y = fungQ(x)
y = 2/x.^2;

fungQ(x) :

function y = fungR(x)
y = (-2/x.^2)*log(x);
And this is the result :

x(i) w(i)
1.00 -0.5000
1.05 -0.3165
1.10 -0.1664
1.15 -0.0424
1.20 0.0612
1.25 0.1485
1.30 0.2226
1.35 0.2860
1.40 0.3406
1.45 0.3880
1.50 0.4301
1.55 0.4678
1.60 0.5019
1.65 0.5329
1.70 0.5613
1.75 0.5874
1.80 0.6116
1.85 0.6342
1.90 0.6553
1.95 0.6752
2.00 ln(2) = 0.693147
7. P 715 no. 1(b)

Approximate the solution to the following partial differential equation using the Backward
Difference Algorithm.

= 0, 0 x 1 , 0 t ;

u(0 , t) = u(1 , t) = 0, 0 t ,

u(x , 0) = 2 sin 2 x , 0 x 1

Use m = 3 , T = 0,1 and N = 2 ,

-( )
and compare your result to the actual solution u(x , t) = 2 sin 2 x

To solve the problem, I’m using MATLAB program. And this is the source code:

clear;
clc;

n=2;
m=3;
l=1;
N=2;
t=0.1;
alpha=1/4;
k=t/N;
h=l/m;
lambda=(alpha^2)*k/(h^2);

for i=1:n
eq(i)=2*sin(2*pi*i*h);
end

for i=1:n
w0(i,1)=eq(i);
end

AA=[ (1+2*lambda) -lambda 0 0 0 0 0 0 0;


-lambda (1+2*lambda) -lambda 0 0 0 0 0 0;
0 -lambda (1+2*lambda) -lambda 0 0 0 0 0 ;
0 0 -lambda (1+2*lambda) -lambda 0 0 0 0;
0 0 0 -lambda (1+2*lambda) -lambda 0 0 0;
0 0 0 0 -lambda (1+2*lambda) -lambda 0 0;
0 0 0 0 0 -lambda (1+2*lambda) -lambda 0 ;
0 0 0 0 0 0 -lambda (1+2*lambda) -lambda ;
0 0 0 0 0 0 0 -lambda (1+2*lambda) ];
iteration=2;
for i=1:iteration

A=AA;

for i=1:n
A(i,n+1)=w0(i,1);
end

for j=1:(n-1)
if (A(j,j)==0)
for p=1:n+1
u=A(j,p);
v=A(j+1,p);
A(j+1,p)=u;
A(j,p)=v;
end
end

jj=j+1;
for i=jj:n
m=A(i,j)/A(j,j);
for k=1:(n+1)
A(i,k)=A(i,k)-(m*A(j,k));
end
end
end

w(n,1)=A(n,n+1)/A(n,n);

for i=n-1:-1:1
S=0;
for j=n:-1:i+1
S=S+A(i,j) *w(j,1);
end
w(i,1)=(A(i,n+1)-S)/A(i,i);
end
w0=w;
end
w

% ------ actual solution----------


for i=1:n
y(i)=2*exp((-pi.^2/4)*t)*sin(2*pi*i*h);
end
y

The results listed in Table below which illustrates the stability of this method

xi wi,50 u(xi, 0.5) | wi,50 − u(xi, 0.5) |


0.0 0 0
0.3333333 1.4730 1.3533 0.1191
0.6666666 -1.4730 -1.3533 0.1191

Вам также может понравиться