Created
December 4, 2009 14:23
-
-
Save folsen/249040 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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