inverting a function with Maple 9.5

Hello everyone,

Can anyone describe me how to invert a function in Maple 9.5? The following, in particular:

piecewise(x<=20, 100-x-(3/80)*x^2+(3/1600)*x^3-2*x, x>=20 and x<=fsolve(1495/16-(201/64)*x+(33/1280)*x^2-(3/25600)*x^3=0), 1495/16-(201/64)*x+(33/1280)*x^2-(3/25600)*x^3)

Thank you in advance.

Ozgur

what is this ???

.......and x<=fsolve(......

Thank you casperyc but I

Thank you casperyc but I don't quite understand; how will fsolve help me in this case?

lemelinm's picture

fsolve is a part of the

definition of the piecewise function.  It give:

 

 

 

About inverting the function, sorry I don't know how to do it.

mario.lemelin@cgocable.ca

Hey Mario, Apparently, I

Hey Mario,

Apparently, I couldn't express myself clearly:

I am trying to invert the piecewise function I wrote in 1-D math and you converted to 2-D math. I know what fsolve is for.

I used the built in procedure "solve" to invert the function, but when I compose the result and the original function I used in "solve", I don't get the identity.

acer's picture

domain, 1-1?

What's the domain of interest here? You'll want function f to be 1-1, where you hope to invert it properly.

Let's look at your function,

f := x -> piecewise(
   x<=20,
   100-x-(3/80)*x^2+(3/1600)*x^3-2*x,
   x>=20 and
   x<=fsolve(1495/16-(201/64)*x+(33/1280)*x^2-(3/25600)*x^3=0),
   1495/16-(201/64)*x+(33/1280)*x^2-(3/25600)*x^3);

plot(f,-100..100);
plot(f,-40..10);
Optimization:-Maximize(f,-40..10);

finv := proc(y, highlow := 'high')
global f;
 if highlow = 'high' then
   fsolve(x -> f(x) - y, -17.37 .. 100);
 else
   fsolve(x -> f(x) - y, -100 .. -17.37);
 end if;
end proc:


And so now, using -17.37 the maximal point as the cut-off between high and low ranges for the domain,

> finv(50); f(finv(50));
                                  16.02900152
 
                                  50.00000001
 
> finv(50,low); f(finv(50));
                                 -38.85067771
 
                                  50.00000001

> finv(f(2),high);
                                  2.000000000
 
> finv(f(-20),low);
                                 -20.00000000

acer

Robert Israel's picture

Inverting

Your function is given by two cubic polynomials, on for x <= 20 and the other for 20 < x <= r where r is a point where the second polynomial is 0.  You don't say what the function should be for x > r.  The function is not one-to-one, but its restriction to the interval [20/3*(1-sqrt(13)), r] is one-to-one, so I assume that's what you want the inverse of.

> f1 := 100-3*x-3/80*x^2+3/1600*x^3;
   f2 := 1495/16-201/64*x+33/1280*x^2-3/25600*x^3;
   r := fsolve(f2 = 0);
> x1 := 20/3*(1-sqrt(13));
   y1 := simplify(eval(f1, x = x1));
   y2 := eval(f1,x=20);
> S1 := simplify(evalc([solve(f1=y,x)])) assuming y>y2, y<y1;

= [40/3*13^(1/2)*cos(1/3*arctan(300*(-31600+1420*y-9*y^2)^(1/2),-71000+900*y))+20/3, -20/3*13^(1/2)*cos(1/3*arctan(300*(-31600+1420*y-9*y^2)^(1/2),-71000+900*y))+20/3-20/3*3^(1/2)*13^(1/2)*sin(1/3*arctan(300*(-31600+1420*y-9*y^2)^(1/2),-71000+900*y)), -20/3*13^(1/2)*cos(1/3*arctan(300*(-31600+1420*y-9*y^2)^(1/2),-71000+900*y))+20/3+20/3*3^(1/2)*13^(1/2)*sin(1/3*arctan(300*(-31600+1420*y-9*y^2)^(1/2),-71000+900*y))]

> evalf(eval(S1,y=y2));

[39.99999999, -40.00000000, 20.00000000]

Oops, there goes the <maple> tag again: that should be [39.99999999, -40.00000000, 20.00000000].

So we want the third branch of the solution.

> S2 := simplify(evalc([solve(f2=y,x)])) assuming y<y2,y>0;
> evalf(eval(S2, y=y2));

[20.00000006, 99.99999999-113.1370850*I, 99.99999999+113.1370850*I]

That should be [20.00000006, 99.99999999-113.1370850*I, 99.99999999+113.1370850*I].

So we want the first branch of this solution.

> finverse:= piecewise(y <= y2, S2[1], y <= y1, S1[3]);

= PIECEWISE([-4/3*(2*(10000+225*y+75*(40000+800*y+9*y^2)^(1/2))^(2/3)-1000-55*(10000+225*y+75*(40000+800*y+9*y^2)^(1/2))^(1/3))/(10000+225*y+75*(40000+800*y+9*y^2)^(1/2))^(1/3), y <= 40],[-20/3*13^(1/2)*cos(1/3*arctan(300*(-31600+1420*y-9*y^2)^(1/2),-71000+900*y))+20/3+20/3*3^(1/2)*13^(1/2)*sin(1/3*arctan(300*(-31600+1420*y-9*y^2)^(1/2),-71000+900*y)), y <= 710/9+130/9*13^(1/2)])

 

 

 

what if the function is not cubic anymore?

Hi Robert,

I worked on your algorithm for a while, and I think I wrote something which would invert cubic functions, which are monotone decreasing in the first quadrant. However, I cannot find the inverse of
' align='absmiddle'>

Solving each piece separately and then picking the branch which gives the smallest error for f^(-1)(f(x))-x does not work anymore, because I get RootOf expressions and Maple tends to return only one value when I evaluate a list of solutions.

Do you have any idea?

Thank you,

Ozgur

acer's picture

allvalues

Have a look at the help-page ?allvalues

minor point: Above, you use the word "evaluate" when it seems you actually mean evaluate an approximation in floating-point. The same term is also misused here. In Maple, the term "evaluation" means something quite distinct, but not that. The routine evalf does floating-point approximate evaluation. See also ?radnormal if you are interested in treatment of expressions containing radicals of exact symbolic values.

acer

this helps!

acer and Robert,

Thanks A LOT for your time and effort.

Acer, I needed an analytical solution, and Robert's code solves the problem.

I didn't give enough background informaton I think: I am only interested in the positive quadrant (x and y are the price and quantity -and when you invert, quantity and price- of Economics). That piecewise function I gave is the monotone cubic spline fit to a given set of data, so it is necessarily one-to-one. So I knew the inverse existed but didn't know how to do it.

Now I just have to find a more automatic way of doing this because I need it for a simulation.

Best,

Ozgur Inal

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}