⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sineg.m

📁 matlab6矩阵微分工具 matlab6矩阵微分工具
💻 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 + -