【问题标题】:Python 3.6: using Simpson's methodPython 3.6:使用辛普森的方法
【发布时间】:2018-11-01 09:40:33
【问题描述】:

我正在尝试使用 Simpson 方法对一组数据进行集成。我发现我可以执行以下操作,如下所示:result=simps(velocity, time, dx=(1/60))。我希望间距以秒为单位而不是分钟(因此为 1/60) - 但更改 dx 的值不会改变我的结果。如何在几秒钟内与 dx 集成?

# import the necessary modules
import numpy as np
import matplotlib.pyplot as plt

# reads the experimnetal data
a=np.loadtxt("VelvstUniform.txt")

# assigns the data columns
time=a[:,0]
velocity=a[:,1]

# graphs in the same figure Sunspots vs Year and LEO vs Year
plt.plot(time,velocity,markersize=10, color="green", marker="o", 
linestyle="-")
plt.xlabel("Time (min)", fontweight="bold", fontsize="large")
plt.ylabel("velocity (miles/hour)", fontweight="bold", fontsize="large", 
color="green")

from scipy.integrate import simps
result=simps(velocity, time, dx=(1/60))

print(result)

【问题讨论】:

    标签: python python-3.x


    【解决方案1】:

    我认为你在这里误解了一些东西:

    dx 改变集成块的宽度,但不改变它们的单位。为此,您必须将您的值乘以您希望的比例因子。而且我认为您更愿意以小时为单位来time,因为您以 mph 为单位测量速度。

    你可以改result;它当前的单位是 min*mi/h,所以你必须乘以 1/60 才能得到以英里为单位的结果。

    【讨论】:

    • 我的错,是的,我的意思是 dx 的几小时到几分钟。
    • 感谢您的帮助。谢谢
    猜你喜欢
    • 2020-02-26
    • 2021-04-19
    • 2016-07-19
    • 1970-01-01
    • 2019-06-08
    • 2018-08-18
    • 2016-01-12
    • 2016-05-05
    • 1970-01-01
    相关资源
    最近更新 更多