Numerical solution of sine-Gordon using RK4

5 views (last 30 days)
mopsus
mopsus on 11 Oct 2022
Edited: mopsus on 11 Oct 2022
I would like to ask you for help with the program.
I am trying to write a program to solve the sine-Gordon equation (with disipation) using the RK4 method.
The equation is:
The initial conditions are
,
And the boundary conditions are
,
.
I wrote this equation as a system of equations:
,
.
However, I stuck on preparing the code. I don't know if I should prepare a separate matrix for the derivative (in the code ddxx_u)? I can't figure out how to run this. May I ask you for help with this code?
clc;
clear all;
v=0.5;
x0=0;
a=0.01;
dx=0.1;
x = -20:dx:20;
dt=0.1;
t = 0:dt:10;
u = zeros(length(t),length(x));
du = zeros(length(t),length(x));
%initial condition
u(1,:) = 4*atan(exp((x-x0)/sqrt(1-v^2)));
du(1,:) = -(2*v/sqrt(1-v^2))*sech((x-x0)/sqrt(1-v^2));
%ddxx_u?
F_xyz = @(du) du;
G_xyz = @(ddxx_u,u,du) ddxx_u-sin(u)-a*du;
for i=1:(length(t))
for j=1:(length(x))
%boundary conditions
if (j==1)
u(i,j)=0;
elseif (j==length(x))
u(i,j)=2*pi;
end
%ddxx_u?
k_1 = F_xyz(du(i,j));
L_1 = G_xyz(ddxx_u(i,j),u(i,j),du(i,j));
k_2 = F_xyz(du(i,j)+0.5*dt*k_1);
L_2 = G_xyz(ddxx_u(i,j)+0.5*dt,u(i,j)+0.5*dt*k_1,du(i,j)+0.5*dt*L_1);
k_3 = F_xyz(du(i,j)+0.5*dt*k_2);
L_3 = G_xyz(ddxx_u(i,j)+0.5*dt,u(i,j)+0.5*dt*k_2,du(i,j)+0.5*dt*L_2);
k_4 = F_xyz(du(i,j)+0.5*dt);
L_4 = G_xyz(ddxx_u(i,j)+0.5*dt,u(i,j)+0.5*dt,du(i,j)+0.5*dt);
u(i,j+1) = u(i,j) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*dt;
du(i,j+1) = du(i,j) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*dt;
end
end
  1 Comment
Torsten
Torsten on 11 Oct 2022
This is a partial differential equation that depends on t and x as independent variables.
Look up "method-of-lines" to see how to solve it.

Sign in to comment.

Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!