ode45 with Two Degrees of Freedom MATLAB

时间:2016-01-26 19:41:09

标签: matlab ode45

我试图用ode45函数求解微分方程,该函数涉及两个自由度,即x和y方向。当我在下面的oem函数中时,我试图将所需的所有四个变量存储到矩阵中以插入ode45,但是我无法通过oem函数识别ds(3)或ds(4)。我尝试过这项工作,但我已经撞墙了。

function odeprob2 
%ode45 function [T, S] = ode45(@oem, linspace(0,0.1,100), [0,2]);
fprintf('Final Position in the X Direction = %4.2f \n', S(end,1));
fprintf('Final Velocity in the X Direction= %4.2f \n', S(end,2));
fprintf('Final Position in the Y Direction = %4.2f \n', S(end,3));
fprintf('Final Velocity in the Y Direction= %4.2f \n', S(end,4));
plot(T, S(:,1), '-k')
xlabel('Time, sec')
ylabel('Position, m')

function ds = oem(t, s)
  %Constants: 
  rad = 15; %mm
  dens = 8000; %kg/m^3
  deno = 980; %kg/m^3
  g = 9.81 ; %m/s^2
ds = zeros(4, 1);
ds(1) = s(2);
ds(2) = ((-1.6) * s(2)) / (((4/3)*pi*(rad^3))*dens);
ds(3) = s(4);
ds(4) = ((((4/3) * pi * (rad^3)) * (dens - deno) * g) - (1.6 * s(4))) / (((4/3) *pi*(rad^3))*dens);

0 个答案:

没有答案