How to write piecewise function in symbolic form?
17 views (last 30 days)
Show older comments
I have to make a piecewise function in symbolic form using the following:
-2 <= t <=-1, t+2,
-1 < t <=1, 1,
1<t <=2, -t+2
otherwise 0
i tried the code below but it seems to be giving me errors. Any idea what I'm doing wrong?
syms x(t)
x(t) = piecewise(-2 <=t && t <=-1, t+2,-1 < t && t <=1,1,1<t && t<=2,-t+2 ,0);
fplot (x(t))
0 Comments
Answers (1)
Paul
on 23 Sep 2021
Use &, not &&
syms x(t)
x(t) = piecewise(-2 < t & t <= -1 , t+2, -1 < t & t <= 1, 1, 1 < t & t <= 2, -t+2, 0)
fplot(x(t),'-o')
0 Comments
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!