“Add” object has no attribute “sinh” error in numerical and symbolic expression?

前端 未结 2 680
面向向阳花
面向向阳花 2021-01-16 19:00

Ultimately, my goal is to numerically differentiate the expression \'u\' (see code) with respect to t, with respect to X and three times with respect to X.

First ide

2条回答
  •  -上瘾入骨i
    2021-01-16 19:36

    u is sympy expression. U in python/numpy. The sp.sinh etc are translated to np.sinh etc.

    U(Y) evaluates this with the numpy array, but t is still a symbol. That produces a numpy object dtype array, with some sort of mix of numbers and symbols. np.sinh(x) is evaluated as [z.sinh() for z in x]. Since most objects, including symbols don't have a sinh method, this raises your error.

    I'm not sure about this, but I suspect you need to lambdify both X and t at once, and evaluate with (Y,T) together, rather than in two steps.

    (Later I may try to demonstrate this with a isympy session.)

提交回复
热议问题