title: Second Order Diff Eq with ode45 in Matlab
body: <p>So I need to solve x''(t) = -x(t)^p  with initial conditions x(0)= 0  and v(0) = x'(0) = v_o = 1.
  The value of the parameter p is 1. </p>
  
  <p>This is what I have:</p>
  
  <pre><code>function [t, velocity, x] = ode_oscilation(p)
  
  y=[0;0;0];
      % transform system to the canonical form
  
      function y = oscilation_equation(x,p)
          y=zeros(2,1);
          y(1)=y(2);
          y(2)=-(x)^p;
          %  to make matlab happy we need to return a column vector
          % so we transpose (note the dot in .')
          y=y.'; 
      end
  
      tspan=[0, 30]; % time interval of interest
  
      [t,velocity,x] = ode45(@oscilation_equation, tspan, 1); 
  
      t = y(:,1);
      xposition=y(:,3);
      velocity=y(:,2); 
  
  end 
  </code></pre>
  
  <p>and this is the error message I receive:</p>
  
  <blockquote>
    <blockquote>
      <p>ode_oscillation(1)
      Error using odearguments (line 91)
      ODE_OSCILLATION/OSCILATION_EQUATION must return a
      column vector.</p>
    </blockquote>
  </blockquote>
  
  <p>Error in ode45 (line 114)
  [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0,
  odeArgs, odeFcn, ...</p>
  
  <p>Error in ode_oscillation (line 17)
      [t,velocity,x] = ode45(@oscilation_equation, tspan,1);</p>