title: Matlab Differential Equations Euler’s method
body: <p>I need help plotting a differential equation ... it keeps coming out all funky and the graph is not what it's supposed to look like.</p>
  
  <pre><code>function [dydt] = diff(y,t)
  
  dydt = (-3*y)+(t*(exp(-3*t)));
  
  end
  
  tI = 0;
  yI = -0.1;
  tEnd = 5;
  dt = 0.5;
  
  t = tI:dt:tEnd;
  y = zeros(size(t));
  y(1) = yI;
  
  for k = 2:numel(y)
      yPrime = diff(t(k-1),y(k-1));
      y(k) = y(k-1) + dt*yPrime;
  end
  
  plot(t,y)
  grid on
  title('Engr')
  xlabel('Time')
  ylabel('y(t)')
  legend(['dt = ' num2str(dt)])
  </code></pre>
  
  <p>That's my code, but the graph is not anything like what it's supposed to look like. Am I missing something like an index for the <code>for</code> statement?</p>
  
  <p><strong>Edit</strong>  </p>
  
  <p>I am getting an error:</p>
  
  <pre><code>Error using diff
  Difference order N must be a positive integer scalar.
  
  Error in diff3 (line 12)
      yPrime = diff(t(k-1),y(k-1));
  </code></pre>