-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathexample8_1.py
32 lines (28 loc) · 994 Bytes
/
example8_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python
## example8_1
from numpy import zeros,array
from run_kut4 import *
from ridder import *
from printSoln import *
def initCond(u): # Init. values of [y,y']; use 'u' if unknown
return array([0.0, u])
def r(u): # Boundary condition residual--see Eq. (8.3)
X,Y = integrate(F,xStart,initCond(u),xStop,h)
y = Y[len(Y) - 1]
r = y[0] - 1.0
return r
def F(x,y): # First-order differential equations
F = zeros(2)
F[0] = y[1]
F[1] = -3.0*y[0]*y[1]
return F
xStart = 0.0 # Start of integration
xStop = 2.0 # End of integration
u1 = 1.0 # 1st trial value of unknown init. cond.
u2 = 2.0 # 2nd trial value of unknown init. cond.
h = 0.1 # Step size
freq = 2 # Printout frequency
u = ridder(r,u1,u2) # Compute the correct initial condition
X,Y = integrate(F,xStart,initCond(u),xStop,h)
printSoln(X,Y,freq)
raw_input("\nPress return to exit")