MATLAB Lax wendroff two step method, matlab programming

hi i have been trying to program a general problem to the lax wednroff technique that when done i can hopefully expand on to model a dam break, before i move on im hoping if someone could tell me if im on the right tracks thanks kyle

function compare
close all;clc;clear all

%intial values
ntime = 1000000; dt=0.00040; nx=100; time = 0; a=1;output=0.4;
%step size calculation
dx= (1/nx);
%create size of u_int vector
u_int = zeros(nx,2);
%create little u_int vector for the initial values of height begining and
%end depending which value of A is used
u_int(nx,2) = 1;
u_int(1,1) = 1;

%loop for the two directions needed
for vec = 1:2
% %lax_wendroff
= lax_wendroff_2(nx,a,output, dt, ntime, time,u_int, vec,dx);
figure(vec)
plot(U(:,vec),'r*');grid on;legend('centered');
hold on
end
end


function = lax_wendroff_2(nx,a,output, dt, ntime, time,u_int, vec,dx);
%compute original size matracies
U=zeros(nx,1);
update = U ;
F = U;
if vec == 1;
U(1,vec)=u_int(1,vec);
A=a;
else
U(nx,vec)=u_int(nx,vec);
A=-a;
end
for p = 1:ntime;
if(time + dt>output); dt=output-time;
end
coeff=dt/dx;
%calculate interim steps
for i = 1:(nx-1)
F(i+1,vec)= ((U(i,vec)+U(i+1,vec))/2) - ((A*coeff)*((U(i+1,vec) - U(i,vec))));
end
for i = 2:(nx-1)
update(i,vec) = U(i,vec) - coeff*A*(F(i+1,vec) - F(i,vec));
end
for i = 2:(nx-1)
U(i,vec) = update(i,vec);
end
time = time + dt;
if time==output
break
end

end
end
 

Want to reply to this thread?

"Lax wendroff two step method, matlab programming" You must log in or register to reply here.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top