Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unpl(i)=u(i)-dt/dx*v*(u(i)-u(i-1));
- %clear workspaces
- clear
- clc
- % define variables
- xmin=-10; % minimum value of x
- xmax=10; % maximum value of x
- N=100; % no. nodes - 1
- dt=0.005; % timestep
- t=0; % time
- tmax=10; % maximum value of time
- v = [1 0 0; 0 1 0; 0 0 2]
- % discretise the domain
- dx= (xmax-xmin)/N;
- x = xmin -dx : dx : xmax + dx;
- % initial conditions
- for x=xmin:dx:xmax
- if x<0
- u0=[0 1 1]
- else
- u0=[1 1 2]
- end
- end
- u=u0;
- unpl=u0;
- % loop through time
- nsteps= tmax/dt;
- for n=1 : nsteps
- % calculate the FOU scheme
- for i = 2 : N+2
- unpl(i)=u(i)-dt/dx*v*(u(i)-u(i-1));
- end
- % update t and u
- t=t+dt;
- u=unpl;
- % plot solution
- plot(x,u,'bo-','markerfacelor','b');
- shg;
- pause(dt);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement