微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

耦合二阶ode的Solve_bvp值错误

如何解决耦合二阶ode的Solve_bvp值错误

我是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_ay_b。 谢谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。