writing and plotting function with multiple conditions

Imagine I have a function like this:
How can I write this function in matlab and plot it between 0 and 1? How can I also compute of this function?
I want to have something like f=@(x) my_func

 채택된 답변

Alan Stevens
Alan Stevens 2021년 1월 3일
편집: Alan Stevens 2021년 1월 3일
One possibility:
f = @(x) 9/5*x*(0<=x & x<1/2)+9/5*(1-x)*(1/2<=x & x<=1);
e.g.
f(0.1)
ans =
0.1800
>> f(0.75)
ans =
0.4500

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

질문:

2021년 1월 3일

편집:

2021년 1월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by