How to achieve myself function?


(Tyler) #1

Hi,
I want to write myself piecewise function y = 1/(x-2) + 3/2 if 0<=x<=4/3 , and y = 1 as x > 4/3.
This is my code:
a = 2.0;
b = 3/2.0;
t_max = 4/3.0;

t1 = x == 0;
t2 = x >= t_max;
x = max(-(x-a),realmin);
y = 1/x + b;
y(t1) = 1;
y(t2) = 0;

I don’t know why "==’’ is wrong , because it my learn from CVX functions.
Hope u help me!


(Tyler) #2

Sorry, y = -inv_pos(-x) + b;


(Tyler) #3

the kind of error :b = newcnstr( evalin( ‘caller’, ‘cvx_problem’, ‘[]’ ), x, y, ‘>=’ );


(Michael C. Grant) #4

Please read this section of the manual and even more importantly, the FAQ. If you cannot build your function according to the limited DCP ruleset, CVX cannot solve it, and that is not a bug.