Vous êtes sur la page 1sur 4

Homework 3

Name

: Nadya Amalia

Student ID

: 20213042

Subject

: Computational Physical Systems (FI5005)

Lecturer

: Dr.rer.nat. Linus Ampang Pasasa

FINITE-DIFFERENCE METHOD
Use the finite-difference method to solve the problem
= + ( 4),

0 4

with (0) = (4) = 0 and = 4 subintervals.


SOLUTION
Analytical Solution
The general solution of the second nonhomogeneous linear equation
can be expressed in the form

)( =
= +

The corresponding homogeneous equation = 0 has characteristic equation


1 = 0
= 1

= 1

Complementary solution

= +
= +

The nonhomogeneous equation has ( = )( 4) = 4. It is a degree 2 polinomial. We

will let be a genetic quadratic polinomial: = + + . It follows ' = 2 + and


'' = 2. Substitute them into the equation

(2 ) ( + + = ) 4
+ (2 = ) 4

The corresponding terms on both side should have the same coefficients, therefore, equating
the coefficients of like terms.
:

= 1

1 :

2 = 0

= 4

= 1

=4

= 2

Therefore, = + 4 2 and = + = + + 4 2.
1

Boundary value conditions


For = 0

For = 4

(0) = (4) = 0

+ (0) + (4)(0) 2 = 0
+ = 2

+ (4) + (4)(4) 2 = 0
+ = 2

Substitute = 2

(2 ) + = 2

+ = 2 2
( ) = 2 2
2 2
=
( )

We obtain = 1,96403 and = 0,03597.

Thus, = 0,03597 + 1,96403 + 4 2.


Numerical Solution

We denote the numerical solution at any point by


=

The two boundary value conditions are = 0 and = 4.


We also have = 4 and

4 0
=
=1

Thus, we have five node points, they are = 0, = 1, = 2, = 3 and = 4.


We are given the data values () = = 0 and () = = 0
By using the approximations

1
( 2 + )

1
' = ( )

'' =
with
in the differential equation we obtain

=1

( 2 + ) =
2 + =

For = 1, = 1, = 0

3 + =

3 + = ( 4)
0 3 + = 1(1 4)
3 + = 3
2

For = 2, = 2

3 + = ( 4)
3 + = 2(2 4)

For = 3, = 3, = 0

3 + = 4

3 + = ( 4)
3 + 0 = 3(3 4)
3 = 3

We obtain the following system of equations

1
1
0
0
0

Or in a compact form as = .

0
0
0
3
1
0
1 3
1
0
1 3
0
0
0

MATLAB Source Code


clc, clear all
% NADYA AMALIA (20213042)
% COMPUTATIONAL PHYSICAL SYSTEMS
% DR.rer.nat. LINUS AMPANG PASASA
% FINITE-DIFFERENCE METHOD
% y"(x) - y(x) = r(x) , r(x)= x(x - 4)
% y(0)= alfa , y(l)= beta
% The definate of the global values
global alfa beta h l;
% Problem Data
alfa = 0;
beta = 0;
l = 4;
n = 4;
h = l/n;
% Making of the vector b
b = zeros(n,1);
b(1) = 0
b(n+1) = 0
for i = 2:n
b(i) = (i-1)*((i-1)-4)
end
% Making of the matrix A
A = zeros(n,n) ;
A(1,1) = 1
A(n+1,n+1) = 1
for i = 2:n
A(i,i-1) = 1
A(i,i) = -3
A(i,i+1) = 1
end
% The solution of the system
y = A\b ;
3

0
0
0
1
1

0
0
1 3

2 = 4
3 3
4 0

ym = linspace(0,4,n+1);
ym(1:n+1) = y;
% The analytical solution's presentment
% y(x) = 0.03597(e^x) + 1.96403(e^(-x)) - x^2 + 4x - 2
e = 2.7182818;
delta = linspace(0,4,100);
u = (0.03597.*(e.^delta)) + (1.96403.*(e.^(-delta))) - (delta.^2) +
(4.*delta) - 2;
subplot(1,2,1);
p = plot(delta, u, '*');
title('Plotting of analytical solution of y"(x) - y(x) = x(x - 4)');
xlabel('x'); ylabel('y(x)');
grid on
set(p, 'Color', 'red')
% Presentment of the approximation
intervall = linspace(0,4,n+1);
subplot(1,2,2);
plot(intervall, ym, '-*') ;
title('Plotting of numerical solution of y"(x) - y(x) = x(x - 4) using
Finite-Difference Method');
xlabel('interval [0,4]'); ylabel('yi');
grid on;

From the calculation for numerical solution we obtain


0

1,85714

= 2,57143
1,85714
0

Thus,
= (1) = 1,85714,

= (2) = 2,57143, and


= (3) = 1,85714

Plotting of analytical solution of y"(x) - y(x) = x(x - 4)

Plotting of numerical solution of y"(x) - y(x) = x(x - 4) using Finite-Difference Method


3

2.5

2.5

1.5

1.5

yi

y(x)= 0,03597ex + 1,96403e(-x) - x 2 + 4x - 2

0.5

0.5

0.5

1.5

2
x

2.5

3.5

0.5

1.5
2
2.5
interval [0,4]

3.5

Vous aimerez peut-être aussi