0% found this document useful (0 votes)
27 views9 pages

Finite Difference Method

This document summarizes solving a second order differential equation using finite differences on a grid. A tridiagonal matrix A is constructed to represent the finite difference approximation. The vector bb is constructed with boundary values. The linear system Au=bb is then solved to find the solution vector u at grid points. Finally, the solution u is plotted.

Uploaded by

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

Finite Difference Method

This document summarizes solving a second order differential equation using finite differences on a grid. A tridiagonal matrix A is constructed to represent the finite difference approximation. The vector bb is constructed with boundary values. The linear system Au=bb is then solved to find the solution vector u at grid points. Finally, the solution u is plotted.

Uploaded by

tanish rajoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

I g0 0 0 0

frP+'' $c
-1 2 -1 0 0 0 of7 L'e d-
0 -1 2 -l 0 0
(1.7)
0 0 -1 2 -l 0

0 0 0 -1 2 -1
0 000 0 1

'i Q1
-d Zdxn2=O
)tV bb

bb
.: Vector(l ..6,0)
bb[l),:20: bbl6l:: l0g
:

20
€c
0
L,: I
1 (1.1 ) 0
(1.8)
(1.2) 0
1
0
fl'--
s.0 Z-
/

100
0.2000000000 (1.3) 6<_
t :: lseq(t, i = 0 ..1, n) I u ,: LinearSolve(A, bb)
[0, 0.2000000000, 0.4000000000, 0.6000000000, 0.8000000000, 1.000000000] (1.4) 20

36
A :: 2.IdentityMatrk(6)
All, t1,: t;Al1,2l t: g
:
(4= 52

68
(1.s)
1

0 (1.5) 84

forifrom 1 to5 do Ati + 1, i) =-1' A[',i* 1] ::-1'916' I00


A
plot(x, u)
1 -1 0000 Ge,pre
-1 2 -1 0 0 0
0 -l 2-1 0 0 $ c aTrtul (1.6)
00 -1 2 -1 0
00 0 -1 2 -1
00 0 0-1 2
All, 1l = 1: AU,2),: 0 : A16, 6l::1 A16,5l = g '
A
(2.5)
A :: 2. IdentityMatrix(6) :

A[1, 1) :: l; A[1,2) :: 0
1

0 (2.6)

fori from 1to5 do Ali+1,i1 =-1' At',i * 1l ::-1'.116'


A
i -i 0 0 0 0
-1 2 -1 0 0 0
0 -1 2 *t 0 0
(2.7\
0 0 -1 2 -t 0
0 0 0 -1 2 -1
0 0 0 0 -1 2
A[], l] = 1 :4fi,21 :: 0 :A[6, 6] :: 1' 1rU,5l :: 6.
A
100000
-1 2 -t 0 0 0
0 -1 2 -t 0 0
(2.8)
0 0 -1 2 -1 0
0 0 0 -1 2 -1
00000i
L bb t= Vector(|..6,x) :

[, bblll t: 20 : bbf6):: 100 :

bb

Q2 20
T restart: 0.2000000000
l
with(LinearAlgebra) :
0.4000000000
I
(2.1) (2.e)
,2 0.6000000000
o
- ----; ulx) = xi 0.8000000000
oir
L._ L 100
1 (2.2) u :: LinearSolve(A, bb)
1

5.0
0.2000000000 (2.3)
y:: fseq(i,i:0..1,n)l
[0, 0.2000000000, 0.4000000000, 0.6000000000, 0.8000000000, 1.000000000] (2.4)
d -->
61^fac'h*
20.
36.8000000000000 d",:- &-r*6\Z/
dx" \ /
53.4000000000000 L:: 1 \--l
(2.10)
69.6000000000000 1

1'
8s.2000000000000 n i: -:=
5.U
i00. 0.2000000000 (3,4)
y :: lseq(i, i=0 ..1, n)l
[0, 0.2000000000, 0.4000000000, 0.6000000000, 0.8000000000, 1.000000000 ] (3.s)

(3.6)
A,: IdenilAtMatrk(6) :
2.
Al1,1l :: l; Al1,2l :: g
1

0 (3.7)

forifrom 1 to5 do Ali + 1,i),:-1' Al',i * 1l ::-1'"o6'


A
1 -1 0 0 0 0

-1 2 -1 0 0 0
Q, 00 -10 -12 -l2 -t0 00 (3.8)

0 0 0 -1 2 -1
0 0 0 0 -t 2
Al1,1l ;: I : A11,2),: 0 : A16,6) e 2' 1tU,5l = -2'
A

100 0 00
-1 2 -t 0 00
0 -1 2 00
(3,e)
0 0 -1 -1 0
000 2 -1
000
[, bb :: Vecbr(l ..6, n2)
b6[1] :: g'
t,v
Q3 bb
i
u ,='u'
1 (3.1)
i
l
(3.2)
0

)
0.04000000000 [,
0.04000000000
L? 0.04000000000
(3.10) Q4
0.04000000000 u (4.1)
0.04000000000 x ,:'xt
x (4.2)
u ,: Linearsolve(A, bb)
0.
u(x)
0.1 80000000000000 u(x) (4.3)

0.320000000000000
(3.1 1) de ,-- J- z(x) :10: # Neumann BC
0.420000000000000 dl
T,:: I
0.480000000000000 (4.4)
1

0.500000000000000 r1
plot(x, u) r'': s.o
0.2000000000 (4.5)
0.5 : a ,: lseq(i,;:0..1, ir) l
(4.6)
[0, 0.2000000000, 0.4000000000, 0.6000000000, 0.8000000000, 1.000000000]

(4.7)
A :: 2'IdentityMatrk(6) :
A[1, 1) ,: t; A[1,2] :: 0
1

0 (4.8)

for ifrom 1 to5 do Ali + I, i) : -t; Ali,i * 1l :: - 1."n6.


A
i -1 0 0 0 0

-1 2 -l 0 0 0

0 -1 2 -1 0 0
(4.s)
0 0 -1 2 -t 0

0 0 0 -1 2 -1
0 0 0 0 -1 2

# For Neumann BC, 2u0 - 2ul : h(f'h lk - 2p)

All, 11,: 1 :AU,21,: 0 : A16,6l :: 2' 11U,51 = -2'


A
10000 0
qion
-l 2 -l 0 0 0

0 -1 2 -1 0 0
(4.10)
0 0 -l 2 -1 0

0 0 0 -1 2 -1
0 0 0 0-2 2

bb ,: Vector( I ..6, 10) :

bbll) t= 10: bbl6l': 10'n2 :

bh
10

10

10
(4.11)
10

10

0.4000000000

u ,: LinearSolve(A, bb)
10.

50.2000000000000
80.4000000000000
(4.12\
1 00.600000000000
i
1 1 0.800000000000 I
I (4.13)
11 1.000000000000 I

plot(x, u) i
t-.
[,
ryQ5
I

\ u;:'u' (s.1)
I
I

i x':'x' (s.2)
i

#Neumann al 0

ae ,: -2J= a(x) :0;


dt'
Lt:10
10 (5.3)

L
).u
2.000000000 (5.4) - 100.
xF fseq(i, i:0..10,r)l - 80.
(5.5)
[0, 2.000000000, 4.000000000, 6.000000000, 8.000000000, 10.00000000] - 60.
(5.11)
(5.6) q (?,) - 40.

A t: 2.IdentityMatrk(6\ : -20.
A11,1):= 1;A[1,2):: g
0.
1

0 (5.7) plot(x, u)

for i from 1 to5 do A[i * 1, i] t: -l;Ali,i * ll ::-i'.r4


A
1 -1 0 0 0 0
-1 2 -t 0 0 0
0 -l 2 -1 0 0 (5.8)
0 0 -1 2 -1 0
0 0 0 -1 2 -l
0 0 0 0-1 2
l[ 1, 1] :: 2 : A[1,2) = -2 A16,6l=1:A16,5l::P'
A
2-2 0 0 0 0
-1 2 -l 0 0 0
0 -1 2 -1 0 0 (5.e)
0 0 -1 2 -1 0
0 0 0 -1 2 -l
00000i
bb :: Vector(l ..6,0) :

# kHS is zero
bblll :: -2'n'10 : bD[6] :: 0
bb
- 40.00000000 - 100
0
(s.12)
0
(5.10)
0

0
,t?,
0 Q6
u ,: LinearSolveA. bb\ u t:'u'
(6.1)
x::tr'
(6.2) 0

0
d
de,: 10 ; z(x) : (cos(t'x)
- )2; 0
(6.10)
dr'
0
Lr:1
1 (6.3) 0

n i: -:-:: 1
0
5.U
0.2000000000 (6.4)
* ,: lseq(t,i:0..1, r)l fori from I to6do bbli)t: (cos(n'.r[;]))2;end:
(6.5) bb
[0, 0.2000000000, 0.4000000000, 0.6000000000, 0.8000000000, 1.000000000]
i
(6.6)
0.6s4508497 I
A :: 2. IdentityMatrix(6) | -5 0.09549lL50246
A[1,1],: 1;Al1,2l ': 0
1 lo: 0.09549150210
(6.11 )

0 (6.7)
0.6s4s084974

forf from 1to5 do Ali+ 1,il E-l' Al',i * 1l ::-1'sr6' 1.

A
1 -1 0 0 0 0 #RIIS is not zero
( (cos(n'xl t l) )2'r
-1 2 -1 0 0 0 bbll)=, l-f.-- - z rc):bn$),--
0 -1 2 -l 0 0 (6.8) bb
0 0 -1 2 -1 0 - 3.996000000
0 0 0 -1 2 -1 0.6545084971
0 0 0 0 -1 2 0.09549150246
(6.12)
A[1,1) =- 2: A[1,2] :: -2 A[6,6] :: 1 : A16,5l t: Q ' 0.09s49150270
A
0.6545084974
2-2 0 0 0 0
0
-1 2 -l 0 0 0
u :: LinearSolve(A, bb\
0 -1 2 -1 0 0 (6.e) - 6.24000000 142000
0 0 -l 2 -1 0 - 4.24200000742000
0 0 0 -1 2 -1
- 2.89850849852000
000001 (6.13)
- 1.6s050849808000
bb :: Vector(\ ..6,0);
- 0.498000000340000
Jrq 0.

t
<
plot(x, u)
(7.5)
t0, 2.500000000, 5.000000000, 7.500000000, 10.000000001

(7.6)
A :: 2.IdentityMatrix(S) :

Alr, tl ,: 1; A11,2) ,: 0
1

0 (7.71

for i from I to 2 do A[i + 1, i] = - k|' A[' + 1, i + l]'::: 2' kl; Ali, i * 1 I :: -7t7,tn6'
for i from 3 to 4 do Aii + l, i) e - 7r2' nr' + 1, i + I I 2' k2; Ali' i * 1 I := - 7'2'tn6'
A
.4[1, 1],: I :AU,2),= 0 :A[5,5) :: 1' 1rt,4] :: 6'
A13,3):: a
-=,- 111 P2
kl +k2 (7.8)

A
10 00 0

-k| 2kl -kt 0 0

0 -kL kt +k2 -k2 0 (7.e)

00 -k2 2 k2 -k2
00 00 1

7\ kl =2'k2 = 4
2
4 (7.10)
A
1 00
00
_1 00
4-2
\1' Q7 0- zo- 40 (7.11)
2-material bar
0 0-4 8-4
tl ::'u'
(7.1)
0 00 01
bb :: Vector(\ ..5,0) :
,.-l
(7.2\ bblLl ,:30.0 : 66[5] :: 59-
bb
30.0
ds:: - -a - ulxl :O: 0
d{ <J
L= l0 \= (7.12)
10 (7.3) D 0

0
L
50.
4.0
2.500000000 (7.4) u :: LinearSolve(A, bb)
y e lseq(i, i:0 ..L, n))
30.0
36.66666666
43.33333333 (7.13)

46.66666666
50.

(8.1)

You might also like