一、

1、IPO描述为:
输入:铅球发射角度、 初始速度(m/s)、 初始高度(m)

处理:模拟铅球飞行,时刻更新铅球在飞行中的位置

输出:铅球飞行距离(m)

可以拆分小的时间段。任意时刻的位置,都是 由前面的位置叠加新的时间段位移引起的,最终的控制条件为,当落地时结束,即y轴坐标为0时结束。微分的思想

(1)

 #from math import pi,sin,cos,radians
import math def main():
angle = eval(input("Enter the launch angle (in degrees):"))
vel = eval(input("Enter the initial velocity (in meters/sec):"))
h0 = eval(input("Enter the initial height (in meters):"))
time = eval(input("Enter the time interval: ")) xpos = 0
ypos = h0 theta = math.radians(angle)
xvel = vel * math.cos(theta)
yvel = vel * math.sin(theta) while ypos >= 0:
xpos = xpos + time * xvel
yvell = yvel - time * 9.8
ypos = ypos + time * (yvel + yvell)/2.0
yvel = yvell print("\nDistance traveled:{0:0.1f}meters.".format(xpos)) if __name__ == "__main__":
main()

(2)画出轨迹

 from math import pi,sin,cos,radians
import turtle def drawLine(x, y):#画线
turtle.pendown()
turtle.goto (x, y) def drawText(x, y,n):
turtle.penup()
turtle.goto (x, y)
turtle.pendown()
turtle.write((float("%2.f"%x)/n,float("%2.f"%y)/n))#注意表达方式,只保留两位小数 def main():
angle = eval(input("Enter the launch angle (in degrees):"))
vel = eval(input("Enter the initial velocity (in meters/sec):"))
h0 = eval(input("Enter the initial height (in meters):"))
time = eval(input("Enter the time interval: "))
n=20#显示系数 xpos = 0
ypos = h0 drawLine(500,0) #初始坐标轴
drawLine(0,0)
drawLine(0,300)
drawLine(0,18) theta = radians(angle)
xvel = vel * cos(theta)
yvel = vel * sin(theta) while ypos >= 0:
xpos = xpos + time * xvel
yvell = yvel - time * 9.8
ypos = ypos + time * (yvel + yvell)/2.0
yvel = yvell
drawLine(xpos*n,ypos*n)
drawText(xpos*n,ypos*n,n) turtle.hideturtle()#隐藏箭头
print("\nDistance traveled:{0:0.1f}meters.".format(xpos)) if __name__=="__main__":
main()

引入turtle库,画出轨迹图

(3)程序模块化

 from math import pi,sin,cos,radians

 def getInputs():
angle=eval(input("enter the launch angle (degree):"))
vel = eval(input("Enter the initial velocity (in meters/sec):"))
h0 = eval(input("Enter the initial height (in meters):"))
time = eval(input("Enter the time interval: "))
return angle,vel,h0,time def getXYComponents(vel,angle):
theta=radians(angle)
x=vel*cos(theta)
y=vel*sin(theta)
return x,y def updatePosition(time,xpos,ypos,xvel,yvel):
xpos=xpos+time*xvel
yvell=yvel-9.8*time
ypos=ypos+(yvell+yvel)*time/2
yvel=yvell
return xpos,ypos,yvel def main():
angle,vel,h0,time=getInputs()
xvel,yvel=getXYComponents(vel,angle)
xpos,ypos=0,h0
while ypos>=0:
xpos,ypos,yvel=updatePosition(time,xpos,ypos,xvel,yvel)
print("distance traveled:{0:0.1f}meters.".format(xpos)) if __name__=="__main__":
main()

Python——铅球飞行计算问题的更多相关文章

  1. 使用python做科学计算

    这里总结一个guide,主要针对刚开始做数据挖掘和数据分析的同学 说道统计分析工具你一定想到像excel,spss,sas,matlab以及R语言.R语言是这里面比较火的,它的强项是强大的绘图功能以及 ...

  2. 使用Python做科学计算初探

    今天在搞定Django框架的blog搭建后,尝试一下python的科学计算能力. python的科学计算有三剑客:numpy,scipy,matplotlib. numpy负责数值计算,矩阵操作等: ...

  3. 使用Python做科学计算初探(转)

    今天在搞定Django框架的blog搭建后,尝试一下python的科学计算能力. python的科学计算有三剑客:numpy,scipy,matplotlib. numpy负责数值计算,矩阵操作等: ...

  4. windows下如何快速优雅的使用python的科学计算库?

    Python是一种强大的编程语言,其提供了很多用于科学计算的模块,常见的包括numpy.scipy.pandas和matplotlib.要利用Python进行科学计算,就需要一一安装所需的模块,而这些 ...

  5. Python之字符串计算(计算器)

    Python之字符串计算(计算器) import re expression = '-1-2*((60+2*(-3-40.0+42425/5)*(9-2*5/3+357/553/3*99/4*2998 ...

  6. Python实现的计算马氏距离算法示例

    Python实现的计算马氏距离算法示例 本文实例讲述了Python实现的计算马氏距离算法.分享给大家供大家参考,具体如下: 我给写成函数调用了 python实现马氏距离源代码:     # encod ...

  7. 使用python装饰器计算函数运行时间的实例

    使用python装饰器计算函数运行时间的实例 装饰器在python里面有很重要的作用, 如果能够熟练使用,将会大大的提高工作效率 今天就来见识一下 python 装饰器,到底是怎么工作的. 本文主要是 ...

  8. 《Python之BMI计算》

    <Python之BMI计算> 前段时间写了个 BMI 因为刚刚开始学 有几个错误 第一个: 厘米我当时也没注意因为觉得去掉0.00的话后面1866666666是正确的BMI值 刚刚去看看去 ...

  9. 用Python进行实时计算——PyFlink快速入门

    Flink 1.9.0及更高版本支持Python,也就是PyFlink. 在最新版本的Flink 1.10中,PyFlink支持Python用户定义的函数,使您能够在Table API和SQL中注册和 ...

随机推荐

  1. npm发布包的那些事

    npm发包的那些事 最近一直在研习关于node的知识,发布包虽然是最基础的一点,但由于一些地方的不注意很容易发生错误,我整理了我可能出现过的一些发布包的过程中的一些error,现在分享给大家: 正确的 ...

  2. disruptor 多生产者多消费者实战 四

    一.创建event类 Order public class Order { private String id; private String name; private double price; ...

  3. 阿里云Tomcat配置

    阿里云Tomcat配置并开放 本文可对以下问题提供参考 服务器 如何配置 Tomcat 配置 端口在监听,但是外网无法访问怎么办 注意事项: 对于阿里云服务器相对较为特殊,因为阿里云服务器除了需要在系 ...

  4. Spring Boot从入门到精通(八)日志管理实现和配置信息分析

    Spring Boot对日志的处理,与平时我们处理日志的方式完全一致,它为Java Util Logging.Log4J2和Logback提供了默认配置.对于每种日志都预先配置使用控制台输出和可选的文 ...

  5. django 从零开始 制作一个图站 1环境的配置以及测试本地服务器

    先使用用virtualenv建立一个虚拟环境 使用pycharm 建立一个django项目 选择虚拟环境和建立一个应用app 其中 tuzhan是项目根目录 user是我们的项目app 中间一些项目文 ...

  6. 微博立场检测 60分Baseline

    AI研习社最近举办了一个比赛--微博立场检测,实际上就是一个NLP文本分类的比赛 Baseline-FastText 我的Baseline方法用的是pkuseg分词+FastText,最好成绩是60, ...

  7. 手把手教你用Abp vnext构建API接口服务

    ABP是一个开源应用程序框架,该项目是ASP.NET Boilerplate Web应用程序框架的下一代,专注于基于ASP.NET Core的Web应用程序开发,也支持开发控制台应用程序. 官方网站: ...

  8. span(行级元素)在不定高的div(块级元素)中垂直居中的方法

    设置父级元素: align-items: center; display: flex;

  9. 什么是yarn,如何使用yarn安装项目依赖

    一.yarn的简介: Yarn是facebook发布的一款取代npm的包管理工具. 二.yarn的特点: 1.速度超快. Yarn 缓存了每个下载过的包,所以再次使用时无需重复下载. 同时利用并行下载 ...

  10. The instance of entity type 'manager' cannot be tracked because another instance with the same key value for {'id'} is already being tracked. When attaching existing entities, ensure that only one ent

    最近在用ASP.NET CORE时遇到一些问题,现记录下: 出现上述错误,即在更新实体数据时出现的错误 services.AddDbContext<StoreContext>(c => ...