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.
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,
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);
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.
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, 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.
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?
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.
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,
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.00000000acer
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.
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.
That should be [20.00000006, 99.99999999-113.1370850*I, 99.99999999+113.1370850*I].
So we want the first branch of this solution.
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
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