How to plot this signal x(๐ก) = (๐ก + 2)๐ข(๐ก + 2) โ 2๐ก๐ข(๐ก) + (2(๐ก โ 4) + 2)๐ข(๐ก โ 4)?
์กฐํ ์: 25 (์ต๊ทผ 30์ผ)
์ด์ ๋๊ธ ํ์
Olivia DeBenedictis
2021๋
4์ 26์ผ
๋๊ธ: Olivia DeBenedictis
2021๋
4์ 28์ผ
I just am unsure of the correct syntax for plotting a signal with unit step. This is what I have so far. It gives me an error saying incorrect dimensions but I don't know where to put . for multiplying.
clear all; close all; clc;
syms t t0
u(t) = piecewise(t<t0, 0, t>=t0, 1);
t = -10:1:10;
xt = (t+2)*u(t+2)-(2*t*u(t))+((2*(t-4)+2)*u(t-4));
plot(t,xt);
axis([0,40,-2,2])
title('x(t) = (t+2)*u(t+2)-(2*t*u(t))+((2*(t-4)+2)*u(t-4))')
xlabel('t')
ylabel('x(t)')
grid;
๋๊ธ ์: 0
์ฑํ๋ ๋ต๋ณ
Clayton Gotberg
2021๋
4์ 26์ผ
ํธ์ง: Clayton Gotberg
2021๋
4์ 26์ผ
One error is in the line
xt = (t+2)*u(t+2)-(2*t*u(t))+((2*(t-4)+2)*u(t-4));
and it is happening because of problems with the size of arrays you're calling. For example, in the first part:
(t+2)*u(t+2)
(t+2) % Adds 2 to each element in t, a 1x21 double
u(t+2) % output of u function on t+2, a 1x21 double
A*B % matrix multiplication - the number of columns in A must equal
% the number of rows in B
When you use *, MATLAB assumes you want matrix multiplication. If you want elements in A to be multiplied by elements in the same place in B, use element-wise multiplication (.*) instead.
To answer your question, anywhere that you want to use element-wise multiplication needs a .* instead of a *
๋๊ธ ์: 2
Clayton Gotberg
2021๋
4์ 26์ผ
Another problem with your code is that you do not clarify what t0 is, so MATLAB is forced to assume it could be anything.
From what you're doing, my guess is that when you say u(t+2), you want the Heaviside function that is zero for t<2 and one for t>=2. If so, you can either change your function
u(t,t0) = piecewise(t<t0, 0, t>=t0, 1);
or you can change how you are thinking about the function. If you have a function
syms t
time = -10:10;
example(t) = piecewise(t<0, 0, t>=0, 1);
and you call
example(time+2)
you are automatically shifting each value in time by 2, as if you had run
piecewise(time+2<0, 0, time+2>=0, 1);
which is the same as
piecewise(time<-2,0,time>=-2,1);
์ถ๊ฐ ๋ต๋ณ (0๊ฐ)
์ฐธ๊ณ ํญ๋ชฉ
์นดํ ๊ณ ๋ฆฌ
Help Center ๋ฐ File Exchange์์ Mathematics์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!