Plotting a Piecewise function?

2 visualizzazioni (ultimi 30 giorni)
Jean
Jean il 5 Dic 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.

Risposte (1)

Matt Fig
Matt Fig il 5 Dic 2012
Modificato: Matt Fig il 5 Dic 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),'.')

Categorie

Scopri di più su Manage Products in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by