writing and plotting function with multiple conditions

8 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Alan Stevens
Alan Stevens el 3 de En. de 2021
Editada: Alan Stevens el 3 de En. de 2021
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

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by