0

我正在解决方程运动,我需要数值积分,所以我决定在 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);
4

1 回答 1

1

也许,我错过了一些东西,但如果你有位移和速度,你唯一需要做的就是区分速度:

% Assuming x(:,1) is the velocity, haven't checked your equations
accel = zeros(size(x(:,1)));
accel(2:end) = diff(x(:,1))./diff(t);

但是,当我尝试在 Octave 上运行您的代码时,ode45无法求解方程。地块看起来像这样:

在此处输入图像描述

您能否在 MATLAB 中获得有意义的位移和速度结果?如果不是,我建议你检查你的方程并确保在尝试推导加速度之前得到合理的结果。

于 2013-12-02T09:47:11.660 回答