Plotting a Piecewise function?

3 visualizaciones (últimos 30 días)
Jean
Jean el 5 de Dic. de 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.

Respuestas (1)

Matt Fig
Matt Fig el 5 de Dic. de 2012
Editada: Matt Fig el 5 de Dic. de 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),'.')

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by