线性波传播至垂直壁面反射形成驻波的动画MATLAB程序
生活随笔
收集整理的這篇文章主要介紹了
线性波传播至垂直壁面反射形成驻波的动画MATLAB程序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近在寫博士論文非常繁忙,很久沒有過啦更新,這次帶來個之前寫的好玩的程序,可以幫助大家理解線性波傳遞以及駐波的形成。
%% linear waves add %% code by JN_CUI %% Variables % eta - water surface profile % u - horizontal velocity of water particle % w - vortical velocity of water particle % zeta - horizontal displacement of water particle % epsilon - vertical displacement of water particle % t - time % x - horizontal coordinate % z - vertical coordinate % k - wavenumber % H - wave height % T - wave period % sigma - phase angle clear;clc; %% Function % Vedio settings Path = 'C:\Users\JunnanCui\Desktop\Sandingwave\'; Folder = 'gif\'; V = VideoWriter([Path,Folder,'linear_wave_add_position3.avi']); % 輸出AVI文件名字 V.FrameRate = 50; % 幀率,50fps V.Quality = 90; % 質量,百分比,90% GIF = [Path,Folder,'linear_wave_add_position3.gif']; open(V); % Wave settings H = 0.5; g = 9.8; T = 1.96134; d = 10; K = g*T^2/(2*pi); fun = @(L1) L1/tanh(2*pi/L1*d)-K; L = Division(fun,0.0001,0,K); k = (2*pi/L); sigma = L/T; c = sigma/k; % k=1; x = 0:0.01:12; x1 = 0:0.5:12; z1 = -1:-0.5:-10; [X,Z] = meshgrid(x1,z1); tt= 0:0.1:20; i=1;for t = 0:0.1:20set(0,'DefaultFigureVisible', 'off');eta1 = H/2*(x<=c*t).*cos(k*x-sigma*t+pi/2);eta2 = H/2*((4*L-x)<=c*t).*cos(k*(-x)-sigma*t+pi/2);Eta = eta1+eta2;u1 = pi*H*(X<=c*t)/T.*cosh(k*(d+Z))/sinh(k*d).*cos(k*X-sigma*t+pi/2);w1 = pi*H*(X<=c*t)/T.*sinh(k*(d+Z))/sinh(k*d).*sin(k*X-sigma*t+pi/2);zeta1 = -H*(X<=c*t)/2.*cosh(k*(d+Z))/sinh(k*d).*sin(k*X-sigma*t+pi/2);epsilon1 = H*(X<=c*t)/2.*sinh(k*(d+Z))/sinh(k*d).*cos(k*X-sigma*t+pi/2);u2 = pi*0.5*H*((4*L-X)<=c*t)/T.*cosh(k*(d+Z))/sinh(k*d).*cos(-k*X-sigma*t+pi/2);w2 = pi*0.5*H*((4*L-X)<=c*t)/T.*sinh(k*(d+Z))/sinh(k*d).*sin(-k*X-sigma*t+pi/2);zeta2 = -0.5*H*((4*L-X)<=c*t)/2.*cosh(k*(d+Z))/sinh(k*d).*sin(-k*X-sigma*t+pi/2);epsilon2 = 0.5*H*((4*L-X)<=c*t)/2.*sinh(k*(d+Z))/sinh(k*d).*cos(-k*X-sigma*t+pi/2); % if i==1XX{i} = X+zeta1-zeta2;ZZ{i} = Z+epsilon1+epsilon2;U = u1-u2;W = w1+w2;plot(XX{i}(1:2:end,1:end),ZZ{i}(1:2:end,1:end),'r.','markersize',15);hold onfor j = 2:2:20if i>=jplot(XX{i-j+1}(1:2:end,1:end),ZZ{i-j+1}(1:2:end,1:end),'r.');hold onendendplot(x,Eta,'b','linewidth',2);hold onplot(x1,x1*0,'r--');hold onfill([2*L,2*L,12.2,12.2],[-10,2,2,-10],[0.8,0.8,0.8]);hold onquiver(X,Z,U,W,'k','linewidth',2,'autoscale','off');title(['t = ',num2str(t,'%.1f'),' s']);xlim([0,13]);ylim([-10,2]);xlabel('X (m)');ylabel('Depth (m)');set(gcf,'position',[100,100,1500,700])set(gca,'fontsize',25);img = gcf;% 輸出GIF文件CurrFrame = getframe(img); % 獲取像素,否則無法顯示動畫imshow(CurrFrame.cdata(1:5:end,1:5:end));writeVideo(V, CurrFrame.cdata); %%% 輸出視頻文件im = frame2im(CurrFrame);[A,map] = rgb2ind(im,256); % 將RGB圖像轉換為索引圖像if t == 0imwrite(A,map,GIF,'gif','LoopCount',Inf,'DelayTime',0.005); % DelayTime表示寫入的時間間隔elseimwrite(A,map,GIF,'gif','WriteMode','append','DelayTime',0.005);endclosei=i+1; end close(V); %%% 關閉視頻輸出Division子函數跟之前隨機波里面的那個函數一樣就不貼了
最后輸出的視頻和GIF是這樣嬸兒的:
總結
以上是生活随笔為你收集整理的线性波传播至垂直壁面反射形成驻波的动画MATLAB程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: h5滚动隐藏滚动条_vue.js-div
- 下一篇: 勤哲excel服务器出入库管理系统,如何