y''' + yy" + (1 - y'^2)= 0 y(0)=0, y'(0)=0, y'(+∞)=1
(The +∞ can be replaced with 4).
The above is a Falkner-Skan equation. I want to get the numerical solution from 0 to 4.
Actually, I have read the book Numerical Methods in Engineering with Python 3, and used the methods in the book, but I cannot get the answer. Perhaps there are some errors in the book.
Here is my code:
"""
solve the differential equation
y''' + yy" + (1 - y'^2)= 0 y(0) = 0 y'(0) = 0,y'(+inf) = 0
"""
import numpy as np
from scipy.integrate import odeint
from printSoln import *
start = time.clock()
def F(x,y): # First-order differential equations
y = np.zeros(3)
F0 = y[0]
F1 = y[2]
F2 = y[2]
F3 = -y[0]*y[2] - (1 - y[1]*y[1])
return [F1,F2,F3]
def init(u):
return np.array([0,0,u])
X = np.linspace(0, 5, 50)
u = 0
for i in range(1):
u += 1
Y = odeint(F, init(u), X)
print(Y)
if abs(Y[len(Y)-1,1] - 1) < 0.001:
print(i,'times iterations')
printSoln(X,Y,freq=2)
print("y'(inf)) = ", Y[len(Y)-1,1])
print('y"(0) =',u)
break
end = time.clock()
print('duration =',end - start)
The code you show is supposed to realize the shooting method to solve boundary value problem by reducing it to the initial value problem (https://en.wikipedia.org/wiki/Shooting_method). However, there are many errors in the code.
By reading documentation (https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.integrate.odeint.html) for
odeintfunction which is a core of the solution, one can find that first argument of theodeintis afunc(y, t0, ...). Therefore, we have to replace the linedef F(x,y):bydef F(y,x):Function
F(y, x)should computes the derivative of y at x. Rewriting the original 3rd order non-linear ODE as a system of three 1st order ODEs one can find that: (a) liney = np.zeros(3)does not make sense, since it forces all derivatives to be zero; (b) it should beF1 = y[1]instead ofF1 = y[2]and (c) lineF0 = y[0]is not necessary and can be deleted.We have already figured out that the code should realize shooting method. It means that at the left boundary we have to set conditions
y(0) = 0, y'(0) = 0which we have from the problem statement. However, to solve initial value problem we need one more condition fory''(0). The idea is that we will solve our system of ODEs with different conditions of the formy''(0) = uuntil for some value ofuthe solution satisfies boundary conditiony'(4) = 1at the right boundary with given tolerance. Hence, for experiment purposes, let's replace linefor i in range(1):byfor i in range(5):and print the value ofy'(4)byprint Y[-1,1]. The output will be:It can be seen that if increment of
u= 1: (a)y'(4)monotonically increase and (b) at u = 1y'(4)=-1.26999326625, at u = 2y'(4)=19.263464565. Therefore, the solution which satisfies boundary conditiony'(4)=1can be found with1<u<2. So, we have to decrease the increment ofuin order to find the solution with higher tolerance.Finaly, we can rewrite the code as follows:
Numerical investigations with

ustep=0.01shows that two diferent solutions are possible. One at0<u<1and another at1<u<2. These solutions are shown below.