簡體   English   中英

嘗試在 Juypter Notebook 的 python 中設置拉普拉斯變換方程時出錯

[英]Error trying to set up laplace transform equation in python in a Juypter Notebook

我的代碼:

import sympy as sympy
from sympy import *
from sympy import exp
from sympy.integrals import inverse_laplace_transform
from sympy.abc import a, t, x, s, X, g, G

init_printing(use_unicode=True)

x, g, X = symbols('x g X', cls = Function)

y0 = 3
v0 = -5 

eqn = Eq(s**2*X - s*y0 - v0 + 2*s*X - y0 - 3*X,laplace_transform(8*exp(-t), t, s) + laplace_transform(DiracDelta(t-1/2),t ,s))

我收到以下錯誤:

TypeError                                 Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/sympy/core/cache.py in wrapper(*args, **kwargs)
     92                 try:
---> 93                     retval = cfunc(*args, **kwargs)
     94                 except TypeError:

8 frames
TypeError: as_base_exp() missing 1 required positional argument: 'self'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/sympy/core/mul.py in flatten(cls, seq)
    291                 #      e
    292                 # o = b
--> 293                 b, e = o.as_base_exp()
    294 
    295                 #  y

TypeError: as_base_exp() missing 1 required positional argument: 'self'

我將如何解決此錯誤代碼?

也許您可以先嘗試在大方程之外聲明函數?

例子:

def L(f):
    return sympy.laplace_transform(f, t, s, noconds=True)

f = sympy.exp(-1*t)

然后在你的大方程中使用它:

L(8*f)

另外,我看不到你已經導入了 laplace_transform,只有 inverse_laplace 變換。

文檔: https://dynamics-and-control.readthedocs.io/en/latest/1_Dynamics/3_Linear_systems/Laplace%20transforms.html

我希望這個答案能激勵你修復這個錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM