Group Abstract Group Abstract

Message Boards Message Boards

Having an Issue with Solve with functions in the equations

GROUPS:
The online instructions for Solve give the following example of solving 2 linear equations:

Solve[-7 + a x + y == 0 && -1 + b x - y == 0, {x, y}]

Giving the following output::

{{x -> 8/(a + b), y -> -((a - 7 b)/(a + b))}}

However, if I define two functions g1 and g2 like this:

g1[x_]:=-7+a x+y   and g2[x_]:=-1+b x-y    (these are the left sides of the two equations in the above example),

and then if I write:  Solve[g1==0, g2==0, {x,y}]

I get the following:

Solve::ivar: -1+b x-y==0 is not a valid variable. >>
Solve[-7 + a x + y == 0, -1 + b x - y == 0, {x, y}]

Why can't I put a function like g1 or g2 into Solve?
POSTED BY: Ken Bures
Answer
11 months ago
The above listing is my first attempt on this forum, so I'm not up to speed on the details of how to enter something. But i see that although I typed in the line 
Solve[g1==0,g2 somehow the got left off immediately after g1 and g2. It probably will do it again here. So please note that what I actually typed has the open square bracket, x, close  square bracket  after g1 and g2 in my Solve expression that does not work.

Ken Bures
POSTED BY: Ken Bures
Answer
11 months ago
According to the error message, -1 + b x - y == 0 appears in the place where Solve expected the variable(s). Try something like
 In[1]:= g1[x_, y_] := -7 + a x + y; g2[x_, y_] := -1 + b x - y;
 
 In[2]:= Solve[{g1[x, y] == 0, g2[x, y] == 0}, {x, y}]
 
 Out[2]= {{x -> 8/(a + b), y -> -((a - 7 b)/(a + b))}}
 
 In[3]:= Solve[g1[x, y] == 0 && g2[x, y] == 0, {x, y}]
 
 Out[3]= {{x -> 8/(a + b), y -> -((a - 7 b)/(a + b))}}
POSTED BY: Ilian Gachevski
Answer
11 months ago
 In[1]:= Solve[-7 + a x + y == 0 && -1 + b x - y == 0, {x, y}]
 
 Out[1]= {{x -> 8/(a + b), y -> -((a - 7 b)/(a + b))}}
 
 In[2]:= g1[x_, y_] := -7 + a x + y;
         g2[x_, y_] := -1 + b x - y;
         Solve[g1[x, y] == 0 && g2[x, y] == 0, {x, y}]
 
 Out[4]= {{x -> 8/(a + b), y -> -((a - 7 b)/(a + b))}}

Note: I make heavy use of the little <> icon towards the right end of the second row above the reply box. That used to provide a single box where code could be pasted and would usually not be corrupted in the process. Now it makes multiple single line boxes when I paste code, but I scrape-n-paste-delete-empty-boxes to accomplish the same. And I check carefully both before and after clicking the Publish button, and repeatedly edit if need be, to get the posting to be something that can be directly scrape-n-pasted into a notebook by the readers.
POSTED BY: Bill Simpson
Answer
11 months ago