问题描述
我是Python的新手,并试图根据scipy.integrate.solve_ode
页面上的代码来解决BVP问题。这是我所做的:
mu=0
eta =1
Vz = 1
def dU_dx(U,x):
return np.vstack((U[1],(((+Vz-mu)*U[0])/eta -U[1]*(1/x))))
def dV_dx(V,x):
return np.vstack((V[1],((-Vz-mu)*V[0] -V[1]*(1/x)-V[1]*(1/x**2))/eta))
#Implement evaluation of the boundary condition residuals:
def bc1(ya1,yb1): #for U
return np.array([ya1[0]-1,yb1[0]])
def bc2(ya2,yb2): #for V
return np.array([ya2[0],yb2[0]])
#Define the initial mesh with 5 nodes:
x = np.linspace(0,1,5)
#This problem is kNown to have two solutions. To obtain both of them,we use two different initial guesses for y. We denote them by subscripts a and b.
y_a = np.full((2,x.size),0.0001) # avoiding divide by zero
y_b = np.full((2,0.0001)
y_a[0] = 1
#Now we are ready to run the solver.
from scipy.integrate import solve_bvp
res_a = solve_bvp(dU_dx,bc1,x,y_a,verbose=2)
#res_b = solve_bvp(dV_dx,y_b)
#Plot
x_plot = np.linspace(10**-6,50,100)
y_plot_a = res_a.sol(x_plot)[0]
#y_plot_b = res_b.sol(x_plot)[0]
import matplotlib.pyplot as plt
plt.plot(x_plot,y_plot_a,label='y_a')
#plt.plot(x_plot,y_plot_b,label='y_b')
plt.legend()
plt.xlabel("x")
plt.ylabel("y")
plt.show()
这给了我错误
“ ValueError:串联轴的所有输入数组维必须完全匹配,但是沿着维1,索引0的数组的大小为1,索引1的数组的大小为5”。
据我所知,它们应该匹配,因为我使用x.size
来构造y_a
和y_b
。
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)