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
Dyuman Joshi 2023년 9월 30일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
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')

카테고리

Help CenterFile Exchange에서 Time Series에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by