机器人学-一道面试题

\(求解过程如下:​\)

\(化简得到:\)

\(y''=100*cos(y)-100*sin(y)\)

\(x''=g=9.81\)

\(对①式进行积分得到如下结果:​\)

\(1/2*y'*y'=100*sin(y)+100*cos(y)+C\)

\(由于y(0)=y'(0)=0, 带入求解得到C=-100,\)

$ y'=dy/dt=10\sqrt2 \sqrt((cos(y)+sin(y)-1))$ ④

$ ④式无法进一步化简,若采用wolfram alpha求解得到复杂的Appell超几何函数,②式进行两次积分得到如下结果$

\(x=1/2*9.81*t*t\)

\(综上转化为求解一阶非线性方程问题,x, y都与给定时间t有关, 采用python语言编程,利用龙格库塔算法进行非线性方程数值求解与绘制(x,y)图\)

最后还是没能实现预期结果。添加一些参看链接,继续对本文补充。个人猜测最后非线性常微分方程还是要转化为线性常微分方程进行求解。
https://en.wikipedia.org/wiki/Nonlinear_system#Nonlinear_differential_equations
https://baike.baidu.com/item/单摆(真实周期推导)

import math
from math import sin,cos
import numpy as np
import matplotlib.pyplot as plt

def runge_kutta(y, t, dt, f):
k1 = dt * f(y, t)
k2 = dt * f(y + 0.5 * k1, t + 0.5 * dt)
k3 = dt * f(y + 0.5 * k2, t + 0.5 * dt)
k4 = dt * f(y + k3, t + dt)
return y + (k1 + 2 * k2 + 2 * k3 + k4) / 6.

if name=='main':
t = 0.
y = 0.
x = 0
dt =0.1 #需要给定步长
ys, ts, xs = [], [], []
def func(y, t):
return 10math.sqrt(2)math.sqrt((sin(y)+cos(y)-1))
while t <= 10:
y = runge_kutta(y, t, dt, func)
x=0.59.81t*t
t += dt
ys.append(y)
ts.append(t)
xs.append(x)

plt.plot(xs, ys, label='Nonlinear_equations')
plt.legend()
plt.show()

posted on 2018-11-08 23:15  冬木景  阅读(759)  评论(0)    收藏  举报

导航