- #1

blizzard12345

- 14

- 0

thanks for any help in advance kyle :)

source for lax Friedrich method: http://www.scribd.com/doc/49845422/33/Lax-Wendroﬀ-Method (page 69, i understand that it is only showing the one step for this source)

my code: (the program in question is a MATLAB script)

while time <= output

%calculate stability CFL condition to ensure stability

%(dt/dx)*(velocity + root(2*g))

wmax=0;

for i = 1:nx

w=abs(uh(i)/h(i)) + sqrt(h(i)*abs(g));

if(wmax<w)wmax=w;

end

end

dt=cfl*dx/wmax;

time = time + dt;

time

%calculate half

for i = 1:nx-1

h_half(i+1) = 0.5*((couple_one(h(i+1),uh(i+1)) + couple_one(h(i),uh(i))) - ((dx/dt)*( h(i+1) - h(i) )));

uh_half(i+1) = 0.5*((couple_two(h(i+1),uh(i+1),g) + couple_two(h(i),uh(i),g)) - ((dx/dt)*( uh(i+1) - uh(i) )));

end

%full time step calcs

for i = 2:nx-1

h(i) = h(i) - (dt/dx)*(h_half(i+1) - h_half(i));

uh(i) = uh(i) - (dt/dx)*(uh_half(i+1) - uh_half(i));

end

%update big H ready for plot

for i = 1:nx

H(i) = h(i);

UH(i) = uh(i);

end