Assigning solve result to function




On Sat, 28 Nov 2009, Dmitry Vinokurov wrote:

< Hello,
< 
< I've got an equation, for example 'x_1 + x_2 = 0' (of course real case
< is not so simple, but it's enough for demonstration) and I need to get
< function F(x_2) from it.
< 
< I tried to use solve for it 'solve(x_1 + x_2 = 0, x_1)' and get 'x_1 = -
< x_2'. Now I couldn't find, how to extract right part of solve result
< into function. Just 'F(x_2) := solve(x_1 + x_2 = 0, x_1)' of course
< doesn't work, it results to 'x_1 = -x_2' instead of wanted '- x_2'.
< 
< Can anybody help with it? And maybe I'm on the wrong path and shouldn't
< use 'solve' for it?
< 
< Thanks in advance.
 
How about

(%i5) eq : sin(x)=u; define(F(u),rhs(part(solve(eq,x),1)));

(%o5) sin(x) = u

solve: using arc-trig functions to get a solution.
Some solutions will be lost.
(%o6) F(u):=asin(u)

You can tweak this if you have multiple solutions, etc.
Leo

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.