小编dam*_*u_d的帖子

Runge Kutta 4 和 python 中的钟摆模拟

我正在尝试制作一个使用 runge kutta 4 绘制钟摆摆动的 python 程序= -(m*g*r/I) * np.sin(y)。我的方程是 angular accelartion 。

请找到我的代码。我对python很陌生。

import numpy as np 
import matplotlib.pyplot as plt 
m = 3.0
g = 9.8
r = 2.0
I = 12.0
h = 0.0025 
l=2.0
cycle = 10.0
t = np.arange(0, cycle, h)
n = (int)((cycle)/h)  
initial_angle = 90.0
y=np.zeros(n)
v=np.zeros(n)
def accel(theta):
  return -(m*g*r/I)*np.sin(theta)
y[0] = np.radians(initial_angle) 
v[0] = np.radians(0.0)
for i in range(0, n-1): 
    k1y = h*v[i]
    k1v = h*accel(y[i])
    k2y = h*(v[i]+0.5*k1v) …
Run Code Online (Sandbox Code Playgroud)

python numpy scientific-computing runge-kutta

1
推荐指数
1
解决办法
3421
查看次数

标签 统计

numpy ×1

python ×1

runge-kutta ×1

scientific-computing ×1