Numerical solution of sine-Gordon using RK4

조회 수: 5 (최근 30일)
mopsus
mopsus 2022년 10월 11일
편집: mopsus 2022년 10월 11일
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
Torsten
Torsten 2022년 10월 11일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by