One dimensional wave function animation

  We know the form of the solution of 1-d wave equation is: $ \ 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} $

  Figure:

 

 

  This is just $ n = 3 $ animation fluctuates over time, i.e.,

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);

f = figure;
loops = 100;
set(gcf, 'Position', get(0,'Screensize'));

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.);
    surf(t,x,z)
    view(150,70)
    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
end

  

Guess you like

Origin www.cnblogs.com/darkchii/p/11563743.html