Plotting damped sine travelling wave equation in Matlab

17 ビュー (過去 30 日間)
Jesse
Jesse 2015 年 2 月 20 日
回答済み: Jesse 2020 年 4 月 24 日
Greetings all,
Please correct me if I am wrong on any of this, but I am trying to plot a damped/attenuating sine wave of the form y(x,t)=Ae^-alpha(x) * sin(wt-Bx + phi).
Granted the sin is not in the exponential, I've been trying to code this up knowing that travelling waves have spatial as well as temporal dimensions.
The code I have after user input is:
x=0:.001:1;
Beta = 2*pi/lambda; %(lambda is user input)
y1=zeros(100,100);
for t=0:.001:1
y1(t,:)=A*sin(Beta*x-w*t + phi).exp(-alpha*x)
end
%A, alpha, w, and phi are user input as well
So I'm getting a "Subscript indices must be either real positive integers or logicals." Where am I going wrong?
Also, I am trying to plot this damped wave - do I need to use plot3? If so, why?
Thanks!
-J
  1 件のコメント
Prasad Reddy
Prasad Reddy 2020 年 4 月 24 日
y1(t,:)=A*sinBeta.*x-w*t+phi).*exp(-alpha.*x)
please check the above equation. it may work.
you need not to use plot3 command.

サインインしてコメントする。

採用された回答

KSSV
KSSV 2020 年 4 月 24 日
編集済み: KSSV 2020 年 4 月 24 日
You index t, is taking zero for the first time. Indices cannot be negative and zero in MATLAB. You need not to use loop, you can follow as below.
clc; clear al ;
A = rand ;
lambda = rand ;
w = rand ;
phi = rand ;
alpha = rand ;
x=0:.001:1;
Beta = 2*pi/lambda; %(lambda is user input)
t=0:.001:1 ;
[X,T] = meshgrid(x,t) ;
Y1 = A*sin(Beta*X-w*T + phi).*exp(-alpha*X) ;
surf(X,T,Y1)

その他の回答 (2 件)

Deepak Gupta
Deepak Gupta 2020 年 4 月 24 日
Your y1 seems to be function of two variables x and t so yes, you will need to use plot3 at it will plot y1 against two variables.
You can try below code to find value of y1:
x=0:.001:1;
t =(0:.001:1)';
Beta = 2*pi/lambda; %(lambda is user input)
y1=zeros(1001,1001); % y1 should have same dimention as x*t matrix.
y1=A*sin(Beta*x-w*t + phi).*exp(-alpha*x)
plot3(t, x, y1)

Jesse
Jesse 2020 年 4 月 24 日
Thanks all but this question was posted 5 years ago, and I think it had to do with some project I was working on at the time.
Thank you again for the responses and your time.

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by