• 一维波动函数动画


      我们知道 1-d 波动方程的解的形式为:$ egin{aligned} u(x, t) &= sum_{n=1}^{infty}sin(frac{npi x}{L})(A_ncos(frac{npi ct}{L}) + B_nsin(frac{npi ct}{L})) \ &= sum_{n=1}^{infty} C_nsin(frac{npi x}{L})sin(frac{npi ct}{L} + heta) \ &= sum_{n=1}^{infty} frac{C_n}{2}left [ cos left [ frac{npi}{L}(x - ct) - heta ight ] - cos left [ frac{npi}{L}(x + ct) + heta ight ] ight ]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^2frac{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

      效果:

      

  • 相关阅读:
    javascript金额千分位的实现
    html中仿GroupBox效果与路径问题
    javascript获取表格的高度
    分布式系统的架构思路
    sharepoint2010 Reporting Services 集成注意
    Ext.MessageBox.updateProgress
    认识RFID
    Extjs 下拉ComboBox分页,图片,多行显示
    MVCFckEditor一些小问题
    MVCFckEditor
  • 原文地址:https://www.cnblogs.com/darkchii/p/11563743.html
Copyright © 2020-2023  润新知