Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 0.28 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function [t_out, y_out] = euler( f, t_int, y0, n )
  2.   t0 = t_int(1);
  3.   tf = t_int(2);
  4.   t_out = linspace(t0, tf, n);
  5.   h = (tf - t0)/(n - 1);
  6.   y_out = zeros(1, n);
  7.   y_out(1) = y0;
  8.  
  9.   for k = 1:(n - 1)
  10.     y_out(k + 1) = y_out(k) + h * f(t_out(k), y_out(k));
  11.   end
  12.  
  13.   return;
  14. end