Lax wendroff Two-step method

조회 수: 10 (최근 30일)
kyle lyth
kyle lyth 2012년 2월 22일
hi i am trying to program a generalised lax wendroff two step method to solve the general equation
du/dt + df(u)/dx = 0
the code i have come up with is as shown below (sorry im not sure how to make it look more tidy)
i belive im doing something wrong in the first step with no F function included, however when i place this in or try to i get a graph that can't possibly be correct
thanks for any help 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
[U] = 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 [U] = 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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Special Functions에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by