Problem graphing a piece-wise function in R2016a??
1 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
Adam
2017-2-2
编辑:Adam
2017-2-2
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;
5 个评论
Walter Roberson
2017-2-6
-9:0.5:9 would be fine. The two-line version was just to make it easier to how the parts went together.
Adam
2017-2-6
t = linspace( -9, 9, 100 )
works fine too if you want to insist on 100 values rather than defining a step. Basically you can create your t vector any way you like. It doesn't even have to have regular steps if you don't want.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!