|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
咳咳,让我算算,3年没泡论坛了,可能出现帖子格式不对,给大家带来麻烦,见谅
回归正题
代码:
- import math
- import decimal as dec
- import numpy as np
- import scipy as sp
- class Model:
- def __dec(self, x):#创建十进制对象
- return dec.Decimal(x)
-
- def __init__(self, a=1.496e11, e=1/60, T=365.25964*sp.constants.day, phi=(66+34/60)/180*math.pi):#初始化
- self.a = self.__dec(a)
- self.e = self.__dec(e)
- self.T = self.__dec(T)
- self.phi = self.__dec(phi)
- self.pi = self.__dec(math.pi)
-
- def Fradium(self, theta):#焦半径计算
- Fradium = self.a * (1 - self.e ** 2) / (1 + self.e * self.__dec(math.cos(theta)))
- return float(Fradium)
-
- def theta_of_t(self, t):#theta(t)的计算,需要用到数值积分,这也是问题的主要出处
- t = self.__dec(t)
- func_of_theta = lambda theta:(1 / (1 + self.e * self.__dec(math.cos(theta)))) ** 2#待积分函数
- res_of_integration = lambda theta:sp.integrate.quad(func_of_theta(theta), 0, theta)#积分结果
- equation = lambda theta:float(res_of_integration(theta) - 2 * self.pi * math.sqrt(1 - self.e**2) * t / (self.T * (1 - self.e ** 2) ** 2))#方程
- root = sp.optimize.root(equation, self.pi)#解方程
- try:
- return float(root)
- except:
- print('error')
- return
- def v_of_planet(self, theta):#行星运行速度(如果没算错)
- theta = self.__dec(theta)
- v = 2 * self.pi * self.a * self.__dec(math.sqrt(1 + self.e ** 2 + 2 * self.e * self.__dec(math.cos(theta)))) / (math.sqrt(1 - self.e ** 2) * self.T)#计算式
- return float(v)
-
- def Phi(self, theta):#阳光直射纬度(如果没算错)
- theta = self.__dec(theta)
- Phi = -math.asin(math.cos(theta) * math.cos(self.phi))
- return float(Phi)
-
- def pos_in_xOy(self, theta):#对于的平面直角坐标系中的坐标
- theta = self.__dec(theta)
- Fradium = self.__dec(self.Fradium(theta))
- x = Fradium * math.cos(theta) + self.a * self.e
- y = Fradium * math.sin(theta)
- return (float(x), float(y))
复制代码
对于上面的数学模型有以下几个问题:
1.如果调用下面语句:
- if __name__=='__main__':
- m = Model()
- print(m.theta_of_t(1))
复制代码
那么运行结果如下
- Warning (from warnings module):
- File "G:\tst\JustACommonModel.py", line 23
- func_of_theta = lambda theta:(1 / (1 + self.e * self.__dec(math.cos(theta)))) ** 2
- DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
- Traceback (most recent call last):
- File "G:\tst\JustACommonModel.py", line 54, in <module>
- print(m.theta_of_t(1))
- File "G:\tst\JustACommonModel.py", line 26, in theta_of_t
- root = sp.optimize.root(equation, self.pi)
- ...
- ValueError: invalid callable given
复制代码
应该是积分函数的调用之类的问题吧,代码较硬,难以解释,有志解决问题的壮士敬请谅解
2:.代码实在过硬,难以解释,就是上面说的
3.精度不足,而利用decimal中的Decimal()创建实例化对象后,会有类型不统一而精度下降或抛出错误
等等诸多问题
还有待有志之士前来挑战这几个难得让我晕头转向的bug
如果代码还存在除上面提到以外的问题还请指正 |
|