dsolve错误:'numpy.ndarray'对象不可调用

时间:2020-11-30 21:20:41
import sympy as sp
sp.init_printing()
%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

dsolve错误:'numpy.ndarray'对象不可调用

Can somebody help me please?

有人可以帮帮我吗?

2 个解决方案

#1


0  

The variable y is a numpy.ndarray, not a callable, which means it cannot be used like a function (or other callable) would: y(); only indexed, like y[]. You probably meant to write sp.Derivative(y[x],x).

变量y是numpy.ndarray,不是可调用的,这意味着它不能像函数(或其他可调用的)一样使用:y();只有索引,比如y []。你可能想写sp.Derivative(y [x],x)。

#2


0  

I suspect that you want to solve a differential equation involving only scalar variables.

我怀疑你想要解决仅涉及标量变量的微分方程。

>>> import sympy as sp
>>> sp.var('x')
x
>>> f = sp.Function('f')
>>> sp.dsolve(sp.Derivative(f(x),x)-(1/(1+x**2)-2*f(x)**2))
Eq(f(x), x**3*(2*C1*(C1 - 1) - 1)/3 + x**5*(C1*(16*C1*(-9*C1 + 1) - 13*C1 + 2) - 20*C1 + 12)/30 + C1 + C1*x + C1*x**4*(13*C1 + 2)/6 - C1**2*x**2 + O(x**6))

If you have an initial condition and need to solve for the arbitary constant then Represent a first order differential equation in numpy might help. (I don't know for sure.)

如果你有一个初始条件并需要求解仲裁常数那么表示numpy中的一阶微分方程可能会有所帮助。 (我不确定。)

#1


0  

The variable y is a numpy.ndarray, not a callable, which means it cannot be used like a function (or other callable) would: y(); only indexed, like y[]. You probably meant to write sp.Derivative(y[x],x).

变量y是numpy.ndarray,不是可调用的,这意味着它不能像函数(或其他可调用的)一样使用:y();只有索引,比如y []。你可能想写sp.Derivative(y [x],x)。

#2


0  

I suspect that you want to solve a differential equation involving only scalar variables.

我怀疑你想要解决仅涉及标量变量的微分方程。

>>> import sympy as sp
>>> sp.var('x')
x
>>> f = sp.Function('f')
>>> sp.dsolve(sp.Derivative(f(x),x)-(1/(1+x**2)-2*f(x)**2))
Eq(f(x), x**3*(2*C1*(C1 - 1) - 1)/3 + x**5*(C1*(16*C1*(-9*C1 + 1) - 13*C1 + 2) - 20*C1 + 12)/30 + C1 + C1*x + C1*x**4*(13*C1 + 2)/6 - C1**2*x**2 + O(x**6))

If you have an initial condition and need to solve for the arbitary constant then Represent a first order differential equation in numpy might help. (I don't know for sure.)

如果你有一个初始条件并需要求解仲裁常数那么表示numpy中的一阶微分方程可能会有所帮助。 (我不确定。)