Lax wendroff two step method, matlab programming

In summary, the conversation is about the programming of a general problem using the lax-wendroff technique and the hope to expand it to model a dam break. The code provided is for comparing the results in two different directions and the conversation ends with a suggestion to include comments for better understanding.
  • #1
blizzard12345
14
0
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 I am hoping if someone could tell me if I am 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 beginning 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
 
Physics news on Phys.org
  • #2
Yes, you are on the right track. The lax-wendroff technique is a numerical method for solving partial differential equations. Your code looks correct, however it would be better to include comments to explain what each line of code is doing.
 

1. How does the Lax Wendroff two-step method work?

The Lax Wendroff two-step method is a numerical method used to solve partial differential equations. It involves discretizing the space and time domains and using a finite difference scheme to approximate the solution at each time step. The method uses a combination of forward and backward differences to achieve second-order accuracy.

2. What are the advantages of using the Lax Wendroff two-step method?

The Lax Wendroff two-step method has several advantages over other numerical methods, including its second-order accuracy, stability, and ability to handle non-linear equations. It also allows for a larger time step size compared to other methods, leading to faster computation times.

3. How is the Lax Wendroff two-step method implemented in MATLAB?

To implement the Lax Wendroff two-step method in MATLAB, you would first need to discretize the space and time domains and define the initial and boundary conditions. Then, you would use a loop to iterate through each time step and calculate the solution at each point using the finite difference scheme. This can be achieved using built-in functions such as diff and interp1 in MATLAB.

4. What are the limitations of the Lax Wendroff two-step method?

Although the Lax Wendroff two-step method has many advantages, it also has some limitations. One limitation is that it is not suitable for hyperbolic equations with discontinuous solutions. It also requires a relatively fine grid resolution to accurately capture the solution, leading to higher computational costs.

5. How can I improve the accuracy of the Lax Wendroff two-step method?

To improve the accuracy of the Lax Wendroff two-step method, you can use higher-order finite difference schemes or incorporate adaptive time stepping. You can also refine the grid resolution to better capture the solution. Additionally, you can use a hybrid approach by combining the Lax Wendroff method with other numerical methods to achieve higher accuracy.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
934
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Programming and Computer Science
Replies
1
Views
939
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • Programming and Computer Science
Replies
4
Views
602
  • Introductory Physics Homework Help
Replies
12
Views
194
  • Advanced Physics Homework Help
Replies
11
Views
1K
  • Programming and Computer Science
Replies
1
Views
942
  • Introductory Physics Homework Help
Replies
1
Views
147
Back
Top