2012年2月17日金曜日

Matlab アニメーションの作り方

Underwater Acoustics の宿題で弦の振動をシュミレーション

アニメーションの作り方は

① plot(x,y)
drawnow
③ pause(0.1)

 pause はアニメーションをゆっくりするためのものなので
別になくてもいい。

以下作ったプログラム

% Set Parameter

clear all, close all
L = 3; % Length of string
h = 1; % Initial displacement
c = 400; % Speed of transverse wave
x = 0:L/100:L; % X-axis
y = 0; % Imposed wave
yy = 0; % One wave

tmin = 0; % Start time
tmax = (L/c)*2; % Time interval
tint = (L/c)/30; % End time

% Linear combination of the four waves

for t = tmin:tint:tmax
y = 0;
    for n = 1:1:100;
        kn = n*pi/L;
        omega = kn*c;
        D=cos(omega*t);
        Amp = (9*h)/((n*pi)^2);
        yy = Amp*sin(n*pi/3)*cos(omega*t)*sin(kn*x);
        y = y + yy;
    end

    plot(x,y,'LineWidth',2)
    axis([0,L,-h,h])
    title(sprintf('time = %5.4f [s]',t),'FontSize',12)  
    xlabel('Length of String','FontSize',12);
    ylabel('Displacement','FontSize',12);
    set(gca,'FontSize',12);
    drawnow
    pause(0.1)
end

0 件のコメント:

コメントを投稿