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

1 #!

/usr/bin/python
2 ## example8_8
3 import numpy as np
4 from LUdecomp5 import *
5
6 def equations(x,h,m): # Set up finite difference eqs.
7 h4 = h**4
8 d = np.ones(m + 1)*6.0
9 e = np.ones(m)*(-4.0)
10 f = np.ones(m-1)
11 b = np.zeros(m+1)
12 d[0] = 1.0
13 d[1] = 7.0
14 e[0] = 0.0
15 f[0] = 0.0
16 d[m-1] = 7.0
17 d[m] = 3.0
18 b[m] = 0.5*h**3
19 return d,e,f,b
20
21 xStart = 0.0 # x at left end
22 xStop = 0.5 # x at right end
23 m = 20 # Number of mesh spaces
24 h = (xStop - xStart)/m
25 x = np.arange(xStart,xStop + h,h)
26 d,e,f,b = equations(x,h,m)
27 d,e,f = LUdecomp5(d,e,f)
28 y = LUsolve5(d,e,f,b)
29 print('\n x y')
30 print('{:14.5e} {:14.5e}'.format(x[m-1],y[m-1]))
31 print('{:14.5e} {:14.5e}'.format(x[m],y[m]))
32 input("\nPress return to exit")
33
34
35

You might also like