regarding the creation of sinewave movie

I need to create a simple travelling wave with fixed amplitude and frequency .
I take help of the frames that is at different time instance the frame of sine wave as a function of position
I use getFrame to capture frame.
But when I run the code. its not the sine wave that I see. and is quiet different from theoretical results .
x=0:pi:3*pi;
halfamp=4;
f=0.666;
k=0.5233; % wave number
v=2; % wave velocity
w=2*pi*f; %angular frequency
theta=0; %phase angle
a1=4
a2=a1;
j=v*t;
count=1;
for j=1:18
plot(x,a1*cos((w*0.5*j)-(k*x)+theta), 'red');
plot(x,a2*cos((w*0.5*j)+(k*x)+theta),'green');
hold on;
plot(x,a1*cos((w*0.5*j)-(k*x)+theta)+a2*cos((w*0.5*j)+(k*x)+theta),'black');
hold off;
axis([0,3*pi,-8,8]);
F(j)=getframe;
count=count+1;
grid on;
end
xlabel('x (in meters)');
ylabel('y (in meters)');
title('electromagnetic sinosoidal waves');
movie(F);
Please help.
Student in need of help!!
Here is my code :

1 Kommentar

Geoff Hayes
Geoff Hayes am 12 Okt. 2015
rose - is the theoretical result the plot coloured in black, or is it something else? Please comment your code so that we know what each plot (red, green, and black) refer too.
Also, why do you not show the red plot and deliberately only show the green and black ones?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

John BG
John BG am 12 Okt. 2015

0 Stimmen

try modifying the L shaped membrane demo to display a 2D pulse propagation. MATLAB has an L shaped membrane demo script, that it is where Mathworks logo comes from, called vibes.m : function vibes %VIBES Vibrating L-shaped membrane. % % This demonstration solves the wave equation for the vibrations % of an L-shaped membrane. The solution is expressed as a linear % combination, with time-dependent coefficients, of two-dimensional % spatial eigenfunctions. The eigenfunctions are computed during % initialization by the function MEMBRANE. The first of these % eigenfunctions, the fundamental mode, is the MathWorks logo. % % The L-shaped geometry is of particular interest mathematically because % the stresses approach infinity near the reentrant corner. Conventional % finite difference and finite element methods require considerable % time and storage to achieve reasonable accuracy. The approach used % here employs Bessel functions with fractional order to match the % corner singularity.
% Copyright 1984-2002 The MathWorks, Inc. % $Revision: 5.14.4.1 $ $Date: 2011/09/03 22:39:29 $
% Eigenvalues. lambda = [9.6397238445, 15.19725192, 2*pi^2, ... 29.5214811, 31.9126360, 41.4745099, 44.948488, ... 5*pi^2, 5*pi^2, 56.709610, 65.376535, 71.057755];
% Eigenfunctions for k = 1:12 L{k} = membrane(k); end
% Get coefficients from eigenfunctions. for k = 1:12 c(k) = L{k}(25,23)/3; end
% Set graphics parameters. fig = figure; set(fig,'color','k') x = (-15:15)/15; h = surf(x,x,L{1}); [a,e] = view; view(a+270,e); axis([-1 1 -1 1 -1 1]); caxis(26.9*[-1.5 1]); colormap(hot); axis off
% Buttons uicontrol('pos',[20 20 60 20],'string',getString(message('MATLAB:demos:shared:LabelDoneLC')),'fontsize',12, ... 'callback','close(gcbf)'); uicontrol('pos',[20 40 60 20],'string',getString(message('MATLAB:demos:shared:LabelSlowerLC')),'fontsize',12, ... 'callback','set(gcbf,''userdata'',sqrt(0.5)*get(gcbf,''userdata''))'); uicontrol('pos',[20 60 60 20],'string',getString(message('MATLAB:demos:shared:LabelFasterLC')),'fontsize',12, ... 'callback','set(gcbf,''userdata'',sqrt(2.0)*get(gcbf,''userdata''))');
% Run t = 0; dt = 0.025; set(fig,'userdata',dt) while ishandle(fig) % Coefficients dt = get(fig,'userdata'); t = t + dt; s = c.*sin(sqrt(lambda)*t);
% Amplitude
A = zeros(size(L{1}));
for k = 1:12
A = A + s(k)*L{k};
end
% Velocity
s = lambda .*s;
V = zeros(size(L{1}));
for k = 1:12
V = V + s(k)*L{k};
end
V(16:31,1:15) = NaN;
% Surface plot of height, colored by velocity.
set(h,'zdata',A,'cdata',V);
drawnow
end;

Kategorien

Mehr zu Acoustics, Noise and Vibration finden Sie in Hilfe-Center und File Exchange

Beantwortet:

am 14 Aug. 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by