Plotting a Piecewise function?

4 views (last 30 days)
Jean
Jean on 5 Dec 2012
Hey guys. I need to graph a piecewise function in MATLAB and I don't know how to do it. On top of that, it is also in radians:
f(θ)
=
(80/π²) θ, -π/2 ≤ θ ≤ π/2;
(80/π) - (80/π²) θ, π/2 ≤ θ ≤ 3π/2
How do I graph it in MATLAB? And other than that, is there a way in MATLAB that I can take that function and turn it into time instead of radians? Thanks a lot.

Answers (1)

Matt Fig
Matt Fig on 5 Dec 2012
Edited: Matt Fig on 5 Dec 2012
First define this in an M-file:
function [F] = myfunc(thet)
% help
F = zeros(size(thet));
idx = -pi/2 <= thet & thet <=pi/2;
F(idx) = 80*thet(idx)/pi^2;
idx = pi/2 <= thet & thet <=3*pi/2;
F(idx) = 80/pi*(1 - thet(idx)/pi);
Now from the command line:
>> t = linspace(-pi/2,3*pi/2,1000);
>> plot(t,myfunc2(t),'.')

Categories

Find more on Manage Products in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!