% This script makes 3 videos. % The first one shows a wave propagating from left to right % The second one shows a wave propagating from right to left % The third one shows the solution for the problem 3 form the chapter 5. % % % Created by M. Caldarola on 27 april 2013. (caldarola@df.uba.ar) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% clear %% parameters f = 1; % Frequency in Hz w = 2*pi*f; % Angular frequency [Hz] c = 1; % phase velocity [m/s] k=w/c; % wave vector [1/m] %% Functions A=1; % wave amplitude (the units depend on th physical meaning of psi L=1; % distance mentioned in the problem. psi1 = @(x,t) A*cos(w.*t-k.*x); % incident wave function psi2 = @(x,t) -A*cos(w.*t+k.*(x-2*L)); % reflected wave function %% vectors for evaluation x = linspace(-3*L,L,10^3); % space vector, from -3L to L t = linspace(0,4/f,10^2); % time vector, from 0 to 4 times the temporal period %% Single plots to check % figure % plot(x,psi1(x,0),'r','Linewidth',2) % hold on % plot(x,psi2(x,0),'k','Linewidth',2) % plot(x,psi1(x,0)+psi2(x,0),'--k','Linewidth',2) % xlabel('x/L','Fontsize',16) % ylabel('\psi(x)','Fontsize',16) % grid on % hold off %% for to generate the movie for one propagating wave (positive phase speed) aviobj = avifile('propagante_der.avi','compression','None'); fig = figure; for i = 1:size(t,2) plot(x,psi1(x,t(i)),'r','Linewidth',2) hold on plot(c*t(i)-3*L,psi1(c*t(i),t(i)),'s','MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',10) hold off ylim([-1.2,1.2]) xlabel('x','Fontsize',16) ylabel('\psi_{derecha}(x)','Fontsize',16) grid on F1 = getframe(fig); aviobj = addframe(aviobj,F1); end close(fig); aviobj = close(aviobj); %% for to generate the movie for one propagating wave (negative phase speed) aviobj = avifile('propagante_izq2.avi','quality',50,'fps',10); fig = figure; for i = 1:size(t,2) plot(x,psi2(x,t(i)),'k','Linewidth',2) hold on plot(-c*t(i)+L,psi2(-c*t(i)+L,t(i)),'s','MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',10) hold off ylim([-1.2,1.2]) xlabel('x','Fontsize',16) ylabel('\psi_{Izquierda}(x)','Fontsize',16) grid on F2 = getframe(fig); aviobj = addframe(aviobj,F2); end close(fig); aviobj = close(aviobj); %% Guia 5 Ej2: Reflexión en un punto fijo. Genero un avifile aviobj = avifile('G5_ej2.avi','compression','None'); fig=figure; for i = 1:size(t,2) plot(x,psi1(x,t(i)),'r','Linewidth',2) hold on plot(x,psi2(x,t(i)),'k','Linewidth',2) plot(x,psi1(x,t(i))+psi2(x,t(i)),'--k','Linewidth',2) xlabel('x','Fontsize',16) ylabel('\psi(x)','Fontsize',16) grid on ylim([-2,2]) plot(c*t(i)-3*L,psi1(c*t(i),t(i)),'s','MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',10) plot(-c*t(i)+L,psi2(-c*t(i)+L,t(i)),'s','MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',10) plot(L,psi1(L,t(i))+psi2(L,t(i)),'s','MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',10) hold off F3 = getframe(fig); aviobj = addframe(aviobj,F3); end close(fig); aviobj = close(aviobj);