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

 采纳的回答

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 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by