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.

조회 수: 12 (최근 30일)
% 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))

답변 (1개)

SAI SRUJAN
SAI SRUJAN 2024년 1월 22일
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!

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by