piecewise

How can I create a piecewise inline function in MATLAB?

I have a function in MATLAB which takes another function as an argument. I would like to somehow define a piecewise inline function that can be passed in. Is this somehow possible in MATLAB? Edit: The function I would like to represent is: f(x) = { 1.0, 0.0 <= x <= 0.5, -1.0, 0.5 < x <= 1.0 where 0.0 <= x <= 1.0 ...

Interpolating 2d data that is piecewise constant on faces

I have an irregular mesh which is described by two variables - a faces array that stores the indices of the vertices that constitute each face, and a verts array that stores the coordinates of each vertex. I also have a function that is assumed to be piecewise constant over each face, and it is stored in the form of an array of values pe...

Constructing piecewise symbolic function in Matlab

I am trying to generate a piecewise symbolic function in Matlab. The reason it has to be symbolic is I want to be able to integrate/differentiate the function afterwards and/or insert actual values. I have the following function: x^3/6 -> 0 < x <= 1 (1/6)*(-3*x^3+12*x^2-12x+4) -> 1 < x <= 2 (1/6)*(3*x^3-24*x^2+60x-44) -> 2 <...

Piecewise list comprehensions in python

What is the easiest/most elegant way to do the following in python: def piecewiseProperty(aList): result = [] valueTrue = 50 valueFalse = 10 for x in aList: if hasProperty(x): result.append(valueTrue) else result.append(valueFalse) return result where hasProperty is some fu...