我正在解决方程运动,我需要数值积分,所以我决定在 Matlab 中使用 ode45。我找到了位移和速度,现在我需要找到角加速度并随时间绘制图。
这是我的代码和功能:
代码:
global r b m2 m3 m4 g I M
% Quantities
r=0.2;
b=0.1;
m2=1;
m3=0.2;
m4=2;
g=9.81;
tspan=0:0.01:2;
% Calculation
I=(m2*r^2)/3
M0=m2*g*b+g*r*(m3+m4)
M=1.2*M0
% Runge- Kutta
[t,x]=ode45(@funkce,tspan,[0 0]);
% Plotting
figure(1);
plot(t,x(:,2));
grid;
figure(2);
plot(t,x(:,1));
grid;
功能:
function v=funkce(t,x);
global r b m2 m3 m4 g I M
% Method
v(1,1)= (x(1)^2*(m4*r^2*cos(x(2))*sin(x(2)))+M-cos(x(2))*m2*g*b+(m3+m4)*g*r)/(I+m3*r^2+m4*r^2*cos(x(2))^2);
v(2,1)= x(1);