Can someone please help me correct the error in my code? I'm trying to construct a superposition of two waves of equal amplitude and very similar frequency to create an envelope wave. Thanks

9 Ansichten (letzte 30 Tage)
close all
clear all
clc
x=1:0.1:300;
%
a=1;%m
h=10;%m
k1=2*pi/(pi/2);%1/m where k=2pi/wavelength
k2=2*pi/(pi/1.95);
g=9.81;%m/s^2
w1=sqrt(g*k1*tanh(k1*h)); %rad/s
w2=sqrt(g*k2*tanh(k2*h));
e= -pi + (2*pi).*rand(1,1);% phase is a random number between -pi and pi
T=100;%s
n=zeros(length(x),T);
t=1:0.1:T;
for m=1:length(t)
n(:,m) = 2*a*cos(((w2-w1)*t(m)*0.5) - ((k2-k1)*x*0.5))) * cos(((w2-w1)*t(m)*0.5) - ((k2-k1)*x*0.5)));
plot(n(:,m),'b-','LineWidth',2);
axis([pi 100*pi -10 10])
title(['Propagating Plane Wave at time, t=' num2str(t(m)) ' s.'])
xlabel('Horizontal Excursion, m')
ylabel('Surface Elevation, m')
drawnow
pause(0.5)
end

Akzeptierte Antwort

Alberto
Alberto am 12 Apr. 2014
Check the parenthesis in the line:
n(:,m) = 2*a*cos( ( (w2-w1)*t(m)*0.5) - ((k2-k1)*x*0.5))) *... cos( ( (w2-w1)*t(m)*0.5) - ((k2-k1)*x*0.5)));
your problem is there, it depends in
close all
clear all
clc
x=1:0.1:300;
%
a=1;%m
h=10;%m
k1=2*pi/(pi/2);%1/m where k=2pi/wavelength
k2=2*pi/(pi/1.95);
g=9.81;%m/s^2
w1=sqrt(g*k1*tanh(k1*h)); %rad/s
w2=sqrt(g*k2*tanh(k2*h));
e= -pi + (2*pi).*rand(1,1);% phase is a random number between -pi and pi
T=100;%s
n=zeros(length(x),T);
t=1:0.1:T;
for m=1:length(t)
n(:,m) = 2*a*cos( ( (w2-w1)*t(m)*0.5) - ((k2-k1)*x*0.5)).*...
cos( ( (w2-w1)*t(m)*0.5) - ((k2-k1)*x*0.5));
plot(n(:,m),'b-','LineWidth',2);
axis([pi 100*pi -10 10])
title(['Propagating Plane Wave at time, t=' num2str(t(m)) ' s.'])
xlabel('Horizontal Excursion, m')
ylabel('Surface Elevation, m')
drawnow
pause(0.5) % this is causin error too, you can delete it
end
  2 Kommentare
trinikotch
trinikotch am 12 Apr. 2014
Bearbeitet: trinikotch am 1 Mai 2015
Thanks its working now but I realize Its not the graph I was trying to plot
Alberto
Alberto am 13 Apr. 2014
The problem was that parenthesis didn't matched: too much parenthesis. Try to rewrite carefully.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by