How ı plot the piecewise function

1 Ansicht (letzte 30 Tage)
can evkuran
can evkuran am 19 Dez. 2018
Kommentiert: Star Strider am 19 Dez. 2018
Hi my main problem is i have a function f(t)=A , t1<t<t2
f(t)=0 , otherwise
t1=2 t2=6 A=2 how can ı plot this function

Antworten (2)

Star Strider
Star Strider am 19 Dez. 2018
Try this:
A = 2;
f = @(t, t1, t2) A.*((t1 < t) & (t < t2)); % Use ‘Logical Indexing’
t = linspace(0, 10);
t1 = 2;
t2 = 6;
figure
plot(t, f(t, t1, t2))
grid
  4 Kommentare
madhan ravi
madhan ravi am 19 Dez. 2018
This answer clearly works but you have defined some file as plot.m please change it or rename it
Star Strider
Star Strider am 19 Dez. 2018
As a work-around (until you re-name your script), try this:
A = 2;
f = @(t, t1, t2) A.*((t1 < t) & (t < t2)); % Use ‘Logical Indexing’
t1 = 2;
t2 = 6;
figure
fplot(@(t) f(t, t1, t2), [0 10])
grid
That should run without error.

Melden Sie sich an, um zu kommentieren.


madhan ravi
madhan ravi am 19 Dez. 2018
Another possible approach:
A = 2;
t1=2;
t2=6;
syms t
f = piecewise(t>t1 & t<t2,A,0) ;
fplot(f,[0 10]) % 0 to 10 represent the domain of the function
  2 Kommentare
can evkuran
can evkuran am 19 Dez. 2018
its saying piecewise is undefined or unexpected
madhan ravi
madhan ravi am 19 Dez. 2018
type ver in command window , suspect you don't have symbolic math toolbox

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Spline Postprocessing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by