以数组为系数的边值问题
Boundary Value Problem with Array as Coefficient
首先我正在解决一个边值问题,然后我重复使用这些结果来解决另一组边值问题。然而,这意味着我在第二组边界值问题中的一个系数是一个数组,当求解器试图这样做时,它的维度不匹配。当我在传递给第二个求解器的函数中插入第一个求解器时,它仍然给我一个维度错误。我不确定如何解决这个问题,如有任何帮助,我们将不胜感激。
# Define mesh and solution array
x = np.linspace(-0.5, 0.5, 50)
y = np.zeros((2, x.size))
y2 = np.zeros((4, x.size))
y2[0] = 2.5*x + 1
y2[1] = 3*x
def fun1(x, y):
# Solve for the Magnetic Field
B, dB = y;
d2B = (alpha/(C_k**2*sigma*zeta))*B -U_0*Q*(1/(zeta*C_k))*(1/(np.cosh(Q*x))**2 - 1/(np.cosh(Q/2))**2)
return dB, d2B
def bc1(ya, yb):
#Define the boundary of the Magnetic Field
return ya[0], yb[0]
def func2(x, y2):
# Call the Magnetic Solver
sol = solve_bvp(fun1, bc1, x, y)
B = sol.y[0]
dB = sol.y[1]
U = -C_k*zeta*sol.y[1]
dU = -C_k*zeta*sol.yp[1]
# define second array
T, dT, M, dM = y2
#set out the equations
d2T = (1/gamma - 1)*(sigma*dU**2 + zeta*alpha*dB**2)#
d2M = -(dM/T)*dT + (dM/T)*theta*(m+1) - (alpha/T)*B*dB
return dT, d2T, dM, d2M
def bc2(ya, yb):
return ya[0] - 1, yb[0] - 4, ya[2], yb[2] - 1
tempdensity = solve_bvp(func2, bc2, x, y2)
定义后bc1
改为
sol1 = solve_bvp(fun1, bc1, x, y)
print(sol1.message)
def func2(x, y2):
# Call the Magnetic Solver
y = sol1.sol(x)
yp = fun1(x,y)
B = y[0]
dB = y[1]
U = -C_k*zeta*y[1]
dU = -C_k*zeta*yp[1]
使用前面的常量我得到了两次 "The algorithm converged to the desired accuracy."
首先我正在解决一个边值问题,然后我重复使用这些结果来解决另一组边值问题。然而,这意味着我在第二组边界值问题中的一个系数是一个数组,当求解器试图这样做时,它的维度不匹配。当我在传递给第二个求解器的函数中插入第一个求解器时,它仍然给我一个维度错误。我不确定如何解决这个问题,如有任何帮助,我们将不胜感激。
# Define mesh and solution array
x = np.linspace(-0.5, 0.5, 50)
y = np.zeros((2, x.size))
y2 = np.zeros((4, x.size))
y2[0] = 2.5*x + 1
y2[1] = 3*x
def fun1(x, y):
# Solve for the Magnetic Field
B, dB = y;
d2B = (alpha/(C_k**2*sigma*zeta))*B -U_0*Q*(1/(zeta*C_k))*(1/(np.cosh(Q*x))**2 - 1/(np.cosh(Q/2))**2)
return dB, d2B
def bc1(ya, yb):
#Define the boundary of the Magnetic Field
return ya[0], yb[0]
def func2(x, y2):
# Call the Magnetic Solver
sol = solve_bvp(fun1, bc1, x, y)
B = sol.y[0]
dB = sol.y[1]
U = -C_k*zeta*sol.y[1]
dU = -C_k*zeta*sol.yp[1]
# define second array
T, dT, M, dM = y2
#set out the equations
d2T = (1/gamma - 1)*(sigma*dU**2 + zeta*alpha*dB**2)#
d2M = -(dM/T)*dT + (dM/T)*theta*(m+1) - (alpha/T)*B*dB
return dT, d2T, dM, d2M
def bc2(ya, yb):
return ya[0] - 1, yb[0] - 4, ya[2], yb[2] - 1
tempdensity = solve_bvp(func2, bc2, x, y2)
定义后bc1
改为
sol1 = solve_bvp(fun1, bc1, x, y)
print(sol1.message)
def func2(x, y2):
# Call the Magnetic Solver
y = sol1.sol(x)
yp = fun1(x,y)
B = y[0]
dB = y[1]
U = -C_k*zeta*y[1]
dU = -C_k*zeta*yp[1]
使用前面的常量我得到了两次 "The algorithm converged to the desired accuracy."