【问题标题】:Integration where constant variables is input and plot function输入常量变量的积分和绘图函数
【发布时间】:2021-09-23 07:14:28
【问题描述】:

我正在做一个 python 项目,我需要计算摩托艇的速度和它的位置。
速度公式为v = v0*e^-bt/m,位置为p = (mv0/b)(1-e^-bt /m) 其中 b 为 14,而 m(质量)和 v0(初始速度)需要由用户输入。毕竟,我还需要绘制函数。

项目要求是:

  1. 请求用户输入初始速度 ????0 和摩托艇的质量 ????。
  2. 沿横截面设置足够的离散/网格点 domain, t = [0,21].( 最终值指定为 21 因为我们 也希望包含 20 个)
  3. 根据公式 (1) 计算船的速度,根据公式 (2) 计算船的位置
  4. 在同一轴上绘制船的速度和位置。
  5. 在图表中设置合适的图例、标题、轴标签和线条颜色。
  6. 输出速度和位置的值。

到目前为止,我只编写了以下代码:

%matplotlib inline
import numpy as np
from scipy import integrate
from scipy.integrate import quad
import matplotlib.pyplot as plt

def f(t):
    return v0*math.exp(-b*t/m) #v = intial velocity, b = constant, t = time, m = mass

def p(t):
    return (m*v)/b*(1-math.exp(-b*t/m))#v = intial velocity, b = constant, t = time, m = mass

b = int(14)
v0 = float(input("What is the initial velocity of the motorboat in m/s? "))
m = float(input("what is the mass of the motorboat in kg? "))
i=[0]

velocity,err = quad(f,0,21)
position,err = quad(p,0,21)
print("The velocity of the boat moving across a lake is ",format(velocity,".2f"),"m/s.")
print("The position of the boat after moving across a lake is ",format(position,".2f"),"m.")

【问题讨论】:

    标签: python matplotlib integration


    【解决方案1】:

    你有几个错误:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-28
      • 2019-08-04
      • 1970-01-01
      相关资源
      最近更新 更多