# How to find inverse of a function in cvx?

There is a problem I’m trying to solve, and these are the facts:
We have f(x) = 2x + 3x^(1.2) + 4.1x^(2.3) . The function g is inverse of f while for y>0 , g(y) has a unique value of z and f(z)=y. Also, there is no close form for function g. So, for each y, g(y) will be the solution of the following optimization problem:
g(y) = min_z( z ): f(z) <= y

Now how to write a cvx function to implement g(y)? (It said that input is a constant value of y . for example y=5 ).

To solve this, I defined function f in a separate script named f:

``````function f = f(x)
f = 2*x + 3*x^(1.2) + 4.1 *x^(2.3);
``````

and then in a new script:

``````cvx_begin
variables z x y
y>=0
f(z)<=y
maximize(z)
cvx_end
``````

It gives me an optimal value of z but how can I implement g(y)? Tried the finverse(f(x),y) but like what has been said, g does not have a close form. I appreciate it if someone helps me in this.

Oh I just found something. I think it means that I define a new function which does compute g(y) using cvx. So I made a new script named g:

``````    function g = g(y)
cvx_begin
variables z
y>=0
f(z)<=y
maximize(z)
cvx_end
g = cvx_optval
``````

and now in the command window or a new script I can give any value of y>0 to the function g, like this:

`g(6)`

And it gives me the g(y) for that constant input. So did I get it right?

Does “New functions via partially specified problems” http://cvxr.com/cvx/doc/advanced.html#new-functions-via-partially-specified-problems show what you want?

1 Like

Yes I think that’s it. Thanks.
( And I should add a “g = cvx_optval” at the end of my script. )