我正在尝试使用python解决这个确切的方程,但似乎无法弄清楚如何
import sympy
import scipy
import numpy
x = sympy.symbols("x")
y = sympy.symbols("y")
M= (1/x + 2*(y**2)*x)
N= (2*y*(x**2) - numpy.cos(y))
My = scipy.diff(M,y)
Nx = scipy.diff(N,x)
print('My=',My,'and Nx=',Nx,'so the equation is NOT an exact equation.')
# NOTE that M is simpler than N, so we use mu(y) for our integrating factor
Q=(Nx-My)/M
print('Q=',Q,'which is only a function of y')
# Using dsolve to find mu
mu=scipy.Function('mu')
IntFact=scipy.dsolve(scipy.diff(mu(y),y)-Q*mu(y),mu(y))
print(IntFact) # Any C will do (except 0 of course), so let C1 = 1
IntFact=scipy.exp(2*y)/y
newM=M*IntFact
newN=N*IntFact
My=scipy.diff(newM,y)
Nx=scipy.diff(newN,x)
print("New ODE is",newM,"+ (",newN.simplify(),")y' = 0")
print('My=',My,'and Nx=',Nx,'so the equation is now an exact equation.')
# Find F(x,y)
intMx=scipy.integrate(newM,x)
intNy=scipy.integrate(newN,y)
print('The integral of M dx is',intMx)
print('The integral of N dy is',intNy)
print('So F(x,y)=',intNy,'and the solution is',intNy,'= C')
主要错误在于此行
N= (2*y*(x**2) - numpy.cos(y))
我不知道如何格式化它,所以我不会收到此错误
TypeError: loop of ufunc does not support argument 0 of type Symbol which has no callable cos method
我已经尝试使用]将cos(y)格式化为符号>
cos = sympy.symbols("cos")
但是我遇到了类似的错误:
TypeError: 'Symbol' object is not callable
特别是因为这条线
N= (2*y*(x**2) - cos(y))
我正在尝试使用python解决这个确切的方程式,但是似乎无法弄清楚import sympy import scipy import numpy x = sympy.symbols(“ x”)y = sympy.symbols(“ y”)M = (1 / x + 2 *(y ** 2)* x)N =(...
您使用的是cos
函数的错误实现。