MATLAB: How to use function like `min` in symfun?(I got an error)

functionsymbolicSymbolic Math Toolbox

For example, i want to create a symbolic function: f(x,y) = min(x-1,y+1);
when f(x,y) = x+y, everything is ok, but when it comes to min, error occured.
syms x y
f = symfun(min([x-1 y+1])),[x y])
I got error like this:
"Unable to convert expression into double array."
Help…

Best Answer

  • You can't use min or max in symbolic variables in matlab. A work around can be this one:
    syms x1 x2 real;
    xlt = symfun(1/2*(x1+x2-abs(x1-x2)),[x1,x2]); %min
    xgt = symfun(1/2*(x1+x2+abs(x1-x2)),[x1,x2]); %max