title: ode45 with Two Degrees of Freedom MATLAB
body: <p>I am trying to solve a differential equation with the ode45 function that involves two degrees of freedom, the x and y directions. When in my oem function below I am trying to store all four variables that I need into a matrix to plug into the ode45, but I cannot get the oem function to recognize ds(3) or ds(4). I've tried working through it but I've hit a wall.</p>
  
  <pre><code>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);
  </code></pre>