我们知道 1-d 波动方程的解的形式为:$ \begin{aligned} u(x, t) &= \sum_{n=1}^{\infty}\sin(\frac{n\pi x}{L})(A_n\cos(\frac{n\pi ct}{L}) + B_n\sin(\frac{n\pi ct}{L})) \\ &= \sum_{n=1}^{\infty} C_n\sin(\frac{n\pi x}{L})\sin(\frac{n\pi ct}{L} + \theta) \\ &= \sum_{n=1}^{\infty} \frac{C_n}{2}\left [ \cos \left [ \frac{n\pi}{L}(x - ct) - \theta \right ] - \cos \left [ \frac{n\pi}{L}(x + ct) + \theta \right ] \right ]\end{aligned} $
如图:
这里仅仅展示 $ n = 3 $ 随时间波动动画,即(加了一点东西):
clear;clc; pi = 3.1415926; L = 5.; n = 3; T0 = 0.5; pho = 1.; c = sqrt(T0/pho); % u = zeros(100, length(x)); % for i=1:100 % u(i,:) = sqrt(2)*sin(n*pi*x/L)*sin((n*pi*c*(i-1))/L + pi/4.); % end % % t = ones(100, length(x)); % for i=1:100 % t(i,:) = t(i,:)*(i/10.); % end % % f1 = figure; % plot3(t,x,u); figure; loops = 100; im = imread('background1.jpg'); cmap = flipud(im); set(gcf, 'Position', get(0,'Screensize')); filename = 'f:/1d_wave_yuyuko.gif'; for i = 0:loops hold off [x,t] = meshgrid(0:.1:5,i:.03:10+i); z = sqrt(2)*sin(n*pi*x/L).*sin((n*pi*c*t)/L + pi/4.); mesh(t,x,z,cmap,'facecolor','texturemap','edgecolor','none','cdatamapping','direct') view(50 - i,60) title('PDE: $$\frac{\partial^2 u}{\partial t^2} = c^2\frac{\partial^2 u}{\partial x^2}, n = 3$$','Interpreter','latex') axis tight manual ax = gca; ax.NextPlot = 'replaceChildren'; axis off drawnow % 保存为 gif frame = getframe(gcf); im = frame2im(frame); [imind,cm] = rgb2ind(im,256); if i == 0 imwrite(imind,cm,filename,'gif', 'Loopcount',inf); else imwrite(imind,cm,filename,'gif','WriteMode','append'); end end
效果: