常量变量为输入和绘图函数的积分

2024-05-20 01:52:57 发布

您现在位置:Python中文网/ 问答频道 /正文

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

课程要求如下:

  1. 请求用户输入初始速度𝑣0和摩托艇的质量𝑚.
  2. 沿横截面设置足够的离散/网格点 域,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.")

1条回答
网友
1楼 · 发布于 2024-05-20 01:52:57

您在这方面几乎没有错误:

相关问题 更多 >