Re: Defining Solve results as variable

*To*: mathgroup at smc.vnet.net*Subject*: [mg70056] Re: Defining Solve results as variable*From*: dimmechan at yahoo.com*Date*: Sun, 1 Oct 2006 04:10:25 -0400 (EDT)*References*: <eflebs$deg$1@smc.vnet.net>

Dear Diana, The following example will demonstrate you one way to follow. Suppose you solve the quadratic equation. Here is the list of solutions. sols = x /. Solve[a*x^2 + b*x + c == 0, x] {(-b - Sqrt[b^2 - 4*a*c])/(2*a), (-b + Sqrt[b^2 - 4*a*c])/(2*a)} And here is one way to define two functions. sols[[j]] is equivalent yo Part[sols,j], (j=1,2). f[b_, a_] := Evaluate[sols[[1]]] g[b_, a_] := Evaluate[sols[[2]]] Information[Evaluate] "Evaluate[expr] causes expr to be evaluated even if it appears as the argument of a function whose attributes specify that it should be held unevaluated." Attributes[Evaluate] = {Protected} And here is some verification that this method works. {f[2, 3], g[3, 4]} {(1/6)*(-2 - Sqrt[4 - 12*c]), (1/8)*(-3 + Sqrt[9 - 16*c])} Solve[f[b, a] == g[b, a], c] {{c -> b^2/(4*a)}} Regards Dimitris Anagnostou Î?/Î? Diana ÎÎ³Ï?Î±Ï?Îµ: > Hi, > > I am trying to write a program which defines a variable with the > results of a Solve equation. > > So, if I write > > Solve[x+1=2,x] > > I get {{x -> 1}} > > I have not been able to figure out how to define a variable to the > result, so that if I then type > > x1 = %, for example, it defines x1 as 1. > > I know this must be simple, but I didn't find it in the Help material. > > Thanks in advance, > > Diana