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 vues (au cours des 30 derniers jours)
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 commentaires
Dyuman Joshi
Dyuman Joshi le 30 Sep 2023
An error occurs in this line -
ylim(-6:6);
This is not how ylim works.
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

Connectez-vous pour commenter.

Réponses (1)

KSSV
KSSV le 30 Sep 2023
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')

Catégories

En savoir plus sur Time Series dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by