Plotting a time series e^(-at) cos((bt) u_s (t)) for two cases, first for a=3 and b=50, then for a=-3 and b=50.
2 次查看(过去 30 天)
显示 更早的评论
I have been trying to plot the time series (e^(-at)*cos(bt)*u_s(t))) for two cases, first for a=3 and b=50, then for a=-3 and b=50 . Plot both cases on the same plot. Let the vertical axis span from -6 to 6 and the horizontal axis from 0 to 1 seconds.
Please help me rewrite this code:
a1=3;
b1=50;
a2 = -3;
b2= 50;
f1 = exp^(-a1*t)*cos(b1*t)*u(t);
f2 = exp^(-a2*t)*cos(b2*t)*u(t);
ts1 = timeseries (f1,0:1);
ts2 = timeseries(f2,0:1);
ts1.Name = 'time series';
ylim(-6:6);
plot(ts1);
hold on
plot(ts2);
2 个评论
Dyuman Joshi
2023-9-30
An error occurs in this line -
ylim(-6:6);
From the documentation - "Specify limits as a two-element vector of the form [ymin ymax], where ymax is greater than ymin."
And you don't need to define the variables as timeseries object. Plot directly, as has been show below.
You can also use fplot
回答(1 个)
KSSV
2023-9-30
clc; clear ;
a1=3;
b1=50;
a2 = -3;
b2= 50;
t = linspace(0,1) ;
f1 = exp(-a1*t).*cos(b1*t) ;
f2 = exp(-a2*t).*cos(b2*t);
plot(t,f1,'r');
hold on
plot(t,f2,'b');
ylim([-6 6])
legend('f1','f2')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!