SHARE
TWEET

Untitled

a guest Dec 16th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function [y,t] = euler(yz, y0, t0, dt, steps)
  2. ys = [y0];
  3. ts = [t0];
  4. u1 = yz-4;
  5. u2 = yz+4;
  6. u = u1;
  7. for i=2:steps
  8.     ts(i) = ts(i-1)+dt;
  9.     if (yz-ys(i-1))>0
  10.         u=u1;
  11.     else
  12.         u=u2;
  13.     end
  14.    ys(i)=ys(i-1)+dt*(3*u-3*ys(i-1));
  15.    end
  16.    y=ys;
  17.    t=ts;
  18.    endfunction
  19.  
  20. [y,t] = euler(20, 0, 0, 0.1, 50);
  21. plot(t,y)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top