SHARE
TWEET

Untitled

a guest Jun 18th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unpl(i)=u(i)-dt/dx*v*(u(i)-u(i-1));
  2.      
  3. %clear workspaces
  4. clear
  5. clc
  6.  
  7. % define variables
  8. xmin=-10;      % minimum value of x
  9. xmax=10;       % maximum value of x
  10. N=100;         % no. nodes - 1
  11. dt=0.005;      % timestep
  12. t=0;           % time
  13. tmax=10;       % maximum value of time
  14. v = [1 0 0; 0 1 0; 0 0 2]
  15.  
  16. % discretise the domain
  17. dx= (xmax-xmin)/N;
  18. x = xmin -dx : dx : xmax + dx;
  19.  
  20. % initial conditions
  21. for x=xmin:dx:xmax  
  22. if x<0
  23.     u0=[0 1 1]
  24. else
  25.     u0=[1 1 2]
  26. end
  27. end
  28.  
  29. u=u0;
  30. unpl=u0;
  31.  
  32. % loop through time
  33. nsteps= tmax/dt;
  34. for n=1 : nsteps
  35.  
  36.  
  37.  
  38.     % calculate the FOU scheme
  39.     for i = 2 : N+2
  40.         unpl(i)=u(i)-dt/dx*v*(u(i)-u(i-1));
  41.     end
  42.  
  43.     % update t and u
  44.     t=t+dt;
  45.     u=unpl;
  46.  
  47.  
  48.     % plot solution
  49.     plot(x,u,'bo-','markerfacelor','b');
  50.     shg;
  51.     pause(dt);
  52.  
  53. end
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