extracting just one variable result from a simultaneous equation

734 views
Skip to first unread message

geoffOst

unread,
Jan 21, 2014, 10:14:23 AM1/21/14
to tins...@googlegroups.com
Consider I have the following:

solve(x+y=1 and x-y=3,x,y)

I get

x=2 and y=-1

I would like a way to get just the x value. Now I have found that IF the solution was say 

x=2 or y=-1

then

exp@>list(x=2 or y=-1, x)

would do the job, but it doesn't work for "and"! I also dabbled with zeros, but that doesn't seem to do simultaneous equations.

Is there a way to do this?

Many thanks in advance,
Geoff.

Nevil Hopley

unread,
Jan 21, 2014, 11:44:09 AM1/21/14
to tins...@googlegroups.com
If you are dealing with Linear Equations, then using the Numeric solver command of 'LinSolve' can help...

linSolve(x+y=1 and x-y=3,x,y)[1]

The [1] in brackets takes the first variable solution (ie, the 'x')
If it was [2], then it would take the second variable solution (ie the 'y')

Nevil

Sean Bird

unread,
Jan 21, 2014, 12:13:00 PM1/21/14
to tins...@googlegroups.com
Good call Nevil.
Like the CAS function "zeros" - for example zeros(x^2+5,x) - results in a list,
so does linsolve. Then you can request which element of the list.
See the attached screen shot for how it appears on the TI-Nspire

- Sean Bird

linsolve.jpg

geoffOst

unread,
Jan 21, 2014, 1:35:39 PM1/21/14
to tins...@googlegroups.com
Thanks Nevil and Sean,

 
If you are dealing with Linear Equations, then using the Numeric solver command of 'LinSolve' can help...

Ah, I see that my minimal example was too minimal! Actually my application uses quite complicated non linear equations, involving some trig functions, squares, roots and the like. All the same, say  Say something like:

solve(x+y=2 and x^(2)-y=3,x,y)

 

Nevil Hopley

unread,
Jan 21, 2014, 2:41:41 PM1/21/14
to tins...@googlegroups.com

If you had solve(x+y=2 and x-y=3,x,y) then it returns "x=5/2and y=-1/2"
To extract the x value only from this answer, type as a new line:
x| x=5/2and y=-1/2
This reads as "x given that x=5/2 and y=-1/2" and it'll return just 5/2 on its own.

Your example of solve(x+y=2 and x^2-y=3,x,y) that had multiple solutions doesn't work in the same way, as when you do the "x|...." line, it doesn't know which value of x to pick, due to the 'or' answer

So, this'll only work when you have a solution of the form "x=... and y=..." and nothing else.

Nevil
 

geoffOst

unread,
Jan 21, 2014, 4:19:56 PM1/21/14
to tins...@googlegroups.com

So, this'll only work when you have a solution of the form "x=... and y=..." and nothing else.

In my case I do come out with just one solution of the form x=...and y=.... yet it doesn't work. As I said, with "or" it works, but not with "and". A pity.

Anyway, thanks for the inputs.
Geoff. 

Don

unread,
Feb 2, 2014, 10:43:38 PM2/2/14
to tins...@googlegroups.com
You can use the part() function to extract the x= value. For example, part(x=1 and y=4,1) would return x=1.

geoffOst

unread,
Feb 3, 2014, 2:59:48 AM2/3/14
to tins...@googlegroups.com
Don,

Many thanks! The part() function is just the part!

Geoff.
Reply all
Reply to author
Forward
0 new messages