MATLAB: Problem graphing a piece-wise function in R2016a?

MATLABpiecewisepiecewise function

I need help graphing a piece wise function in Matlab, the function is
y(t) = y1=-3t^2+5 when t>=0 and y2=3t^2+5 when t<0
with t in [-9,9]
I have tried many different ways to graph this, and I honestly can't figure it out. Any help would be greatly appreciated!

Best Answer

It is very simple when you think about it in components. You can create y piece-wise and then plot a graph as normal.
e.g.
t = -9:9; % Or whatever granularity you want for t
y( t >= 0 ) = -3*t( t >= 0 ).^2 + 5;
y( t < 0 ) = 3*t( t < 0 ).^2 + 5;