?? sineg.m
字號:
% The script file sineg.m solves the sine-Gordon equation% u_tt-u_xx-sin u on the real line using one of the following% differentiation matrices: (1) Hermite, (2) sinc, or (3) Fourier.% The solution is displayed as a mesh plot.% J.A.C. Weideman, S.C. Reddy 1998method = input(' Which method: (1) Hermite, (2) sinc, (3) Fourier? '); N = input(' Order of differentiation matrix: N = ? ');tfinal = input(' Final time: t = ? ');if method == 1b = input(' Scaling parameter for Hermite method: b = ? ');[x,D] = herdif(N,2,b); % Compute Hermite differentiation matrices D = D(:,:,2); % Extract second derivativeelseif method == 2h = input(' Step-size for sinc method: h = ? ');[x,D] = sincdif(N,2,h); % Compute sinc differentiation matrices D = D(:,:,2); % Extract second derivativeelseif method == 3L = input(' Half-period for Fourier method: L = ? ');[x,D] = fourdif(N,2); % Compute Fourier second derivative x = L*(x-pi)/pi; % Rescale [0, 2pi] to [-L,L] D = (pi/L)^2*D;end u0 = zeros(size(x)); % Compute initial conditions v0 = 2*sqrt(2)*sech(x/sqrt(2)); w0 = [u0; v0]; tspan = [0:tfinal/40:tfinal];options = odeset('RelTol',1e-6,'AbsTol',1e-6); % Options for ODE45 [t,w] = ode45('sgrhs', tspan, w0, options, D); % Solve ODEsu = w(:,1:N); % Extract u variable from solution arraymesh(x,t,u); view(30,30); % Generate a mesh plot of u
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -