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 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Alberto
2014-4-12
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 个评论
Alberto
2014-4-13
The problem was that parenthesis didn't matched: too much parenthesis. Try to rewrite carefully.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!