How ı plot the piecewise function

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

답변 (2개)

Star Strider
Star Strider 2018년 12월 19일

1 개 추천

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

can evkuran
can evkuran 2018년 12월 19일
Adsız.pngits giving me that empty graph im new in matlab i cannot understand the problem
Star Strider
Star Strider 2018년 12월 19일
You have apparently written your own script file and saved it as ‘plot.m’.
Re-name it to ‘myPlot.m’, or to something that does not overshadow plot, or any other MATLAB functions.
Then my code should run without error.
madhan ravi
madhan ravi 2018년 12월 19일
This answer clearly works but you have defined some file as plot.m please change it or rename it
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.

댓글을 달려면 로그인하십시오.

madhan ravi
madhan ravi 2018년 12월 19일

0 개 추천

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

can evkuran
can evkuran 2018년 12월 19일
its saying piecewise is undefined or unexpected
madhan ravi
madhan ravi 2018년 12월 19일
type ver in command window , suspect you don't have symbolic math toolbox

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

질문:

2018년 12월 19일

댓글:

2018년 12월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by