Solving Linear convection equation (wave equation) by using 3rd order Runge Kutta scheme

14 visualizaciones (últimos 30 días)
Hi!
I am solving the wave equation by using the 3rd order RK scheme. The attached photo shows the problem.
I have managed to make the other schemes work but I think I am not implementing the 3rd order RK correctly. My code is attached below:
% MAE 5093 Homework #5- Due November 13th, 2018
%% Problem 1 C)
%% Code written by Saad Saleem
% % This MATLAB code solves linear convection equation by 3rd order RK and
% compares it with exact solution
clear all
close all
N=100; %No. of grid points
Tmax=1; % time period=1
alpha=1; %given
h=0.01; %given value of delX
delt=0.005;
maxt=Tmax/delt; %Number of time steps
c=alpha*delt/h; %c=0.5
u=zeros(N+1,maxt+1 ); %Initializing the matrix that will fill in 'u'values
x=zeros(N+1,1);%There is only 1 column but N+1 rows
% Initial condition
for i=1:N+1
x(i)=(i-1)*h ;
u(i,1)=sin(2*pi*x(i ));
end
for k=1:maxt
u0 = u(N,k ); %This is to implement the periodic BC
u(1,1)=u(1,k)-c/2*(u(2,k)-u0);
u(1,2)=3/4*u(1,k)+0.25*u(1,1)-c/8*(u(2,1)-u0);
u(1,k+1)=1/3*(u(1,k))+2/3*u(1,2)-c/3*(u(2,2)-u0);
% u(1,k+1)=u(1,k)-c/2*(u(2,k)-u0)+c^2/2*(u(2,k)-2*u(1,k)+u0 ); %Once you do the initial call, start filling in the next
for i=2:N
u(i,1)=u(i,k)-c/2*(u(i+1,k)-u(i-1,k));
u(i,2)=3/4*u(i,k)+0.25*u(i,1)-c/8*(u(i+1,1)-u(i-1,1));
u(i,k+1)=1/3*(u(i,k))+2/3*u(i,2)-c/3*(u(i+1,2)-u(i-1,2));
% u(i,k+1) =u(i,k)-c/2*(u(i+1,k)-u(i-1,k))+(c^2)/2*(u(i+1,k)-2*u(i,k)+u(i-1,k ));
end
uNp2 = u(2,k);
u(N+1,1)=u(N+1,k)-c/2*(uNp2-u(N,k));
u(N+1,2)=3/4*(u(N+1,k))+0.25*(u(N+1,1))-c/8*(uNp2-u(N,1));
u(N+1,k+1)=1/3*(u(N+1,k))+2/3*(u(N+1,2))-c/3*(uNp2-u(N,2));
end
% plot(x,u(:,10))
plot(x,u(:,10),x,u(:,20),x,u(:,30),x,u(:,40),x,u(:,50),x,u(:,60),x,u(:,70),x,u(:,100))Pb5.PNG
  2 comentarios
Torsten
Torsten el 13 de Nov. de 2018
Be careful: The notation of the Runge-Kutta method in your homework assignment is misleading.
The superscripts (1) and (2) do not indicate the time step (like the superscripts (n) and (n+1)), but intermediate stages of the Runge-Kutta-method in the computation of u^(n+1) from u^(n).
Best wishes
Torsten.
Saad Saleem
Saad Saleem el 13 de Nov. de 2018
Torsten ,
Ah interesting - so like, how will the syntax vary then ?

Iniciar sesión para comentar.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by