I normally create anonymous function in order to avoid creating extra m-file if the function is simple enough. For example if I want to integrate the function f(x)=x(adsbygoogle = window.adsbygoogle || []).push({}); ^{2}+x, I just write a simple matlab script like

myfun=@(x) x.^2 + x;

quad(myfun,0,1)

But how do we create an anonymous function for the following function

[tex]

f(x)=\left\{\begin{array}{ccc}x,&\mbox{ } 0 \leq x <1\\

1-x, & \mbox{ } 1 \leq x <2\\

0 , & \mbox{ elsewhere } \end{array}\right.

[/tex]

The function look simple to me and I know how to write a function m-file for it. But I want to avoid it. Is it possible to create an anonymous function for it?

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab function

Loading...

Similar Threads - Matlab function | Date |
---|---|

Working with Edge function in MATLAB | Mar 7, 2017 |

Matlab Does MatLab have this kind of function? | Jan 15, 2017 |

Matlab error matrix function | Apr 25, 2016 |

Matlab Plotting a 3d function | Apr 1, 2016 |

Fit with implicit nonlinear function - Matlab | Oct 19, 2015 |

**Physics Forums - The Fusion of Science and Community**