【发布时间】:2021-12-13 04:47:44
【问题描述】:
import math
import numpy as np
import matplotlib.pyplot as plt
import simpy as sp
init_printing()
var('x,y,z')
a = math.sqrt(10/7)
c = (y-math.sqrt(18/7)-1)
b = np.sin(math.pi/2*c)-z
f = lambda x,y,z: x**2+y**2+z**2-4
g = lambda x, y, z: (9/2)*(x**2+z**2)+y**2-9
h = lambda y, z: np.sqrt(10/7) * np.sin((np.pi/2) * y - np.sqrt(18/7)-1)- z
F = [[f(x, y, z)],
[g(x, y, z)],
[h(y, z)]]
当我尝试定义函数 h(x) 时,我明白了:
AttributeError Traceback (most recent call last)
AttributeError: 'Add' object has no attribute 'sin'
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
<ipython-input-68-da3a7e28861c> in <module>
10 a = math.sqrt(10/7)
11 c = (y-math.sqrt(18/7)-1)
---> 12 b = np.sin((math.pi/2*c))-z
13
14
TypeError: loop of ufunc does not support argument 0 of type Add which has no callable sin method
我尝试将函数分成 a、b 和 c 部分,以便更容易发现错误。现在我知道var('x, y, z') 和np.sin()/math.sin() 有问题,但我找不到解决方法。
【问题讨论】:
-
首先,您的错误出现在第一行中。无需发布其余代码并污染问题。二、
var是什么?它在哪里定义? (init_printing()也未定义,但无论如何我认为这无关紧要。)总的来说,我认为您将 NumPy 和 SimPy 混为一谈,但您的问题中没有足够的信息来提供正确的答案。