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
조회 수: 7 (최근 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!