Skip to content

Instantly share code, notes, and snippets.

@folsen
Created December 4, 2009 14:23
Show Gist options
  • Save folsen/249040 to your computer and use it in GitHub Desktop.
Save folsen/249040 to your computer and use it in GitHub Desktop.
function unew = burger(u,d,dt,bdry)
N = length(u);
dx = 1/(N);
sup = d*dt/dx^2;
main = 1*ones(N,1)-u*dt/dx-2*d*dt/dx^2*ones(N,1);
sub = u*dt/dx + d*dt/dx^2*ones(N,1);
unew = sub.*backshift(u) + main.*u + sup.*fwdshift(u);
%handle boundary conditions
bdryleft = bdry;
bdryright = 0;
unew(1) = bdryleft;
unew(end) = bdryright;
end
function u = fwdshift(u)
temp = u(end);
for i = 2:length(u)
u(i) = u(i-1);
end
u(1) = temp;
end
function u = backshift(u)
temp = u(1);
for i = 2:length(u)
u(i-1) = u(i);
end
u(end) = temp;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment