If I evaluate Solve[f[x,y]==0,x], I get a bunch of solutions like:
{{x -> something g[y]}, {x -> something else}}, etc.
Now I want to convert each of those x->somethings into a function. Typically, my requirements are low, and my function f[x] is at the most a cubic, with straightforward solutions for x. So I’ve always just defined g1[y_]:=something, g2[y_]:=... etc, manually.
However, for a function that I have now, Solve outputs a complicated polynomial running 4 pages long, and there are 4 such solutions. I’ve tried reducing to simpler forms using Simplify, Collect, Factor etc, but it just seems irreducible.
Is there a way I can automatically assign them to functions? (It’s extremely hard to scroll through pages and copy each one… and I have to look for where the next one begins!)
Something like: {g1[y_], g2[y_], g3[y_]} = output of Solve?
It appears Simon beat me to an answer (I am glad that StackOverflow gives me a pop-up to let me know!), therefore I will take a different approach. You should know how to use the output of Solve directly, as quite a few times it will be convenient to do that.
Starting with
Here are some things you can do.
Find the solutions to
xfora == 7Plot the solutions
Evaluateis used here not out of necessity for basic function, but to allow the Plot function to style each solution separatelyDefine a new function of
afor the second solutionNotice the use of
=rather than:=hereHere is an alternative to Simon’s method for defining functions for each solution
The function is then used with the syntax
gg[1][17]to mean the first solution, anda == 17These uses do generally require that
a(in this example) remain unassigned.