My piecewise function graph is not showing

조회 수: 5 (최근 30일)
John Grand
John Grand 2021년 5월 25일
댓글: Asmit Singh 2021년 5월 26일
I'm trying to plot the the function below, here is what I have
f(x) = 2x x ∈ [0, 0.5]
2x − 1 x ∈ (0.5, 1]
syms x
f(x)=piecewise((0<=x)&(x<=0.5),2*x,(0.5<=x)&(x<=1),2*x(-1),6);
fplot(f(x));
grid on;

채택된 답변

Asmit Singh
Asmit Singh 2021년 5월 25일
It is my understanding that you need to visualize the function you have provided as text, ie
The code that you have provided, mentions 2*x(-1) instead of 2*x-1. The following code illustrates the changes :
syms x
f(x)=piecewise((0<=x)&(x<=0.5),2*x,(0.5<=x)&(x<=1),2*x-1,6);
fplot(f(x));
grid on;
  댓글 수: 2
John Grand
John Grand 2021년 5월 25일
ohhh i see, but why is there a 6 at the end?
Asmit Singh
Asmit Singh 2021년 5월 26일
The 6 at the end denotes the value of the functions, when none of the conditions are matched, I assumed that it was your default value. You can have a look at the documentation for the piecewise function for further details.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by