# How to Solve this “First-order wave equation” using Euler’s time-stepping series to obtain a graph similar to above. Solve this using Runga Kutta time-stepping series also.

9 visualizaciones (últimos 30 días)
ayushman srivastava el 3 de Feb. de 2022
Respondida: SAI SRUJAN el 22 de En. de 2024
% This program describes a moving 1-D wave
% using the finite difference method
clc
close all;
%%
% Initialization
Nx= 480; % x-Grid
dx= 3/480; % Step size
x(:,1)= (0:Nx-1)*dx;
f= 125.7; % Wave number
U(:,1)= -16*(x(:,1)-1/2).^2
% U(:,1) = exp(-16*(x(:,1)-1/2).^2);
U(:,1)= exp(U(:,1));
U(:,1)= U(:,1).*sin(f*x(:,1))
%U(:,1)= exp(-16*(x(:,1)-1/2).^2)%sin*(f*x(:,1))
%U(:,1)= U(:,1).*sin(f*x(:,1))
mpx= (Nx+1)/2; % Mid point of x-axis
% (Mid point of 1 to 3= 2 here)
T= 10; % Total no. of time step
f= 125.7; % Wave number
dt= 0.000625; % time-step
t(:,1)= (0:T-1)*dt;
v= 1; % wave velocity
c=v*(dt/dx); % CFL condition
s1= floor(T/f);
%%
% Initial condition
x=0:.001:3;
u=@(t)exp(-16*(x-(.75*t+.5)).^2).*sin(125.7*x);
plot(x,u(0))
figure
plot(x,u(2))
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

SAI SRUJAN el 22 de En. de 2024
Hi ayushman,
I understand that you are trying to solve the first-order wave equation using two different numerical time-stepping methods: Euler's method and the Runge-Kutta method.
The Euler method is a explicit time-stepping approach. To update each grid point 'i' at the subsequent time step 'n+1', you can employ the following formula within your code:
% Euler Method
for n = 1:T-1
for i = 2:Nx
U(i, n+1) = U(i, n) - c * (U(i, n) - U(i-1, n));
end
end
The Runge-Kutta method is a more accurate method than Euler's method. The second-order Runge-Kutta method (RK2), also known as the midpoint method, can be applied to the wave equation as illustrated below:
% Runge-Kutta Method (RK2)
for n = 1:T-1
for i = 2:Nx
k1 = -c * (U(i, n) - U(i-1, n));
k2 = -c * (U(i, n) + 0.5 * k1 - U(i-1, n) - 0.5 * k1);
U(i, n+1) = U(i, n) + k2;
end
end
Please follow the provided algorithmic outlines and make necessary adjustments for the boundary conditions as you proceed with your implementation.
I hope this helps!
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Runge Kutta Methods en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by