-
Notifications
You must be signed in to change notification settings - Fork 0
/
nonlinShoot_Burden.py
100 lines (72 loc) · 2.56 KB
/
nonlinShoot_Burden.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import numpy as np
import matplotlib.pyplot as plt
def method(a, b, alpha, beta, Nx, tol, Niter):
h = (b-a)/Nx
k = 0
tk = (beta-alpha)/(b-a)
w1 = np.zeros(Nx+1)
w2 = np.zeros(Nx+1)
while (k<=Niter):
w1[0] = alpha
w2[0] = tk
u1 = 0
u2 = 1
for i in range(1, Nx+1):
x = a + (i-1)*h
k11 = h*w2[i-1]
k12 = h*f(x , w1[i-1] , w2[i-1] )
k21 = h*(w2[i-1] + 0.5*k12)
k22 = h*f(x+0.5*h, w1[i-1]+0.5*k11 , w2[i-1] + 0.5*k12)
k31 = h*(w2[i-1] + 0.5*k22)
k32 = h*f(x+0.5*h, w1[i-1] + 0.5*k21, w2[i-1] + 0.5*k22)
k41 = h*(w2[i-1] + k32)
k42 = h*f(x+h, w1[i-1]+k31, w2[i-1]+k32)
w1[i] = w1[i-1] + (k11 + 2*k21 + 2*k31 + k41)/6
w2[i] = w2[i-1] + (k12 + 2*k22 + 2*k32 + k42)/6
kt11 = h*u2
kt12 = h*(fy(x, w1[i-1], w2[i-1])*u1 + fyt(x, w1[i-1], w2[i-1])*u2)
kt21 = h*(u2 + 0.5*kt12)
kt22 = h*(fy(x+0.5*h, w1[i-1], w2[i-1])*(u1+0.5*kt11) + fyt(x+0.5*h, w1[i-1], w2[i-1]*(u2+0.5*kt12)))
kt31 = h*(u2 + 0.5*kt22)
kt32 = h*(fy(x+0.5*h, w1[i-1], w2[i-1])*(u1 + 0.5*kt21) + fyt(x+0.5*h, w1[i-1], w2[i-1])*(u2+0.5*kt22))
kt41 = h*(u2+kt32)
kt42 = h*(fy(x+h, w1[i-1], w2[i-1])*(u1+kt31) + fyt(x+h, w1[i-1], w2[i-1])*(u2+kt32))
u1 = u1 + (1/6)*(kt11 + 2*kt21 + 2*kt31 + kt41)
u2 = u2 + (1/6)*(kt12 + 2*kt22 + 2*kt32 + kt42)
test = np.abs(w1[-1]-beta)
if test < tol:
x = np.zeros(Nx+1)
for i in range(0, Nx+1):
x[i] = a + i*h
sol = np.hstack((x.reshape(Nx+1,1), w1.reshape(Nx+1,1), w2.reshape(Nx+1,1)))
return sol
tk = tk - (w1[-1]- beta)/u1
k += k
#-------------------------------------------
def f(x, y, yp):
mu = 0.3
omega = 0.5
return (1-omega**2)*y - 2*y**3 + 3*mu*y**5 # RHS
#---
def fy(xp, z, zp):
mu = 0.3
omega = 0.5
return (1-omega**2) - 6*z**2 + 15*mu*z**4 #d(RHS)/d(psi)
#---
def fyt(xpp, zpp ,zppp):
return 0 #d(RHS)/d(psi')
#---
a = 0 # interval
b = 10
alpha = 1
beta = 0 # we should give ""beta""" inside the method because we want
# y'(b) = beta
Nx = 20
Nmax = 5
tol = 1e-5
x = np.zeros(Nx)
h = (b-a)/Nx
for i in range(0, Nx):
x[i] = a + (i)*h
sol = method(a,b,alpha,beta,Nx,tol,Nmax)
print(sol)