我想为我的日出学课程开发一个情节,并且问题提供了一个分段函数来描述恒星中“流体”的动力学,就好像它是一回事它的这一点,如果它是另一个它的。我一遍又一遍地接收这个'Mul' object cannot be interpreted as an integer
,但我正在使用实数中的数字,而不仅仅是整数集。我不知道如何解决这个问题,需要指导。代码如下。如何用多变量在Python中定义分段函数
import sympy as sy
from sympy import *
from sympy.physics.units import Unit
import numpy as np
import sys
import math
import scipy as sp
from scipy import special
phi = Symbol('phi', Variable = True)
x = Symbol('x', Variable = True, Real = True)
t = Symbol('t', Variable = True, Real = True)
xi = Symbol('xi', Function = True)
Solar_Radius = Symbol('R', Constant = True, unit = "meters")
Sound_Speed = Symbol('c', Constant = True, unit = "meters per second", Real = True)
gamma = Symbol('gamma', Constant = True)
gravity = Symbol('g', Constant = True, unit = "meters per second per second")
Solar_Radius = 6.963 * 10 ** 6
gamma = 5/3
g = 274.8265625336
gas_constant = 8201.25
c = 8.1 * 10 ** 3
for t in range(0,x/c):
xi[x,t] = 0
for t in range(x/c,00):
xi[x,t] = (1/2)*sy.exp(gamma*g*x/(2*c**2))*mpmath.besselj(0, (gamma*g/(2*c)*sy.sqrt(t**2 - ((x/c)**2))),derivative = 0)
完全回溯:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-50-3506376f1686> in <module>()
----> 1 for t in range(0,x/c):
2 xi[x,t] = 0
3 for t in range(x/c,00):
4 xi[x,t] = (1/2)*sy.exp(gamma*g*x/(2*c**2))*mpmath.besselj(0, (gamma*g/(2*c)*sy.sqrt(t**2 - ((x/c)**2))),derivative = 0)
TypeError: 'Mul' object cannot be interpreted as an integer
清理进口。然后把这个复杂的语句分解成多个步骤,看看错误会来自哪一行,直到你知道什么操作或对象出错为止。 – Harrichael
三大“混乱”中的每一个都是分开的,如果那是误导,我很抱歉。问题在for循环中开始,我不知道为什么。我不知道bessel函数是否清楚,直到我首先得到这个结果 – anabstudent
看来(x/c)不能被解释为整数。你有没有看过是什么样的物体?有一个整数值有意义吗?如果是这样,请查看类型为(x/c)的对象类型,找到定义该类型的库以及Google“库类型整数表示形式”。 – Harrichael