Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[mg16853] extracting lhs or rhs of equations

1,041 views
Skip to first unread message

Kevin J. McCann

unread,
Apr 5, 1999, 3:00:00 AM4/5/99
to
Two ways. I made the equation a little more complicated just to make sure
it works with more stuff on the LHS.

Method 1 (easier to see)

eq1 = (Sin[x] + Cos[x])^2 + 4/(2 + 3*x) == x;

eq1[[1]]
4/(2 + 3*x) + (Cos[x] + Sin[x])^2

eq1[[2]]
x

Method 2 (more in the spirit of Mathematica and pattern matching)

eq1
4/(2 + 3*x) + (Cos[x] + Sin[x])^2 == x

eq1/.(x_ == y__)->x
4/(2 + 3*x) + (Cos[x] + Sin[x])^2

eq1/.(x_ == y_)->y
x

Kevin


----- Original Message -----
From: David P. Johnson <joh...@ae.msstate.edu>
Subject: [mg16853] extracting lhs or rhs of equations


> Let's say I have an expression like:
>
> In[1]:= eq1= Sin[x] == x;
>
> Is there a way to get just the left-hand side or right-hand side of the
> equation? Something like:
>
> In[2]:= LHS[eq1]
> Out[2]:= Sin[x]
>
> TIA.
>
> --
> David
> ->(Signature continues here)
>
>

Jean-Marie THOMAS

unread,
Apr 5, 1999, 3:00:00 AM4/5/99
to
Suppose you have:
eq=lhs==rhs
Using FullForm is often a good start when trying to understand the way
Mathematica puts things together:
FullForm[eq]
So your tools should look like:
First[eq]
Last[eq]

Hope this helps,


****************************************
Jean-Marie THOMAS
mailto:jmth...@agat.net
Conseil et Audit en Ingenierie de Calcul
Strasbourg, France
http://www.agat.net
****************************************

BobH...@aol.com

unread,
Apr 5, 1999, 3:00:00 AM4/5/99
to

In a message dated 4/2/99 4:24:32 AM, joh...@ae.msstate.edu writes:

>Let's say I have an expression like:
>
> In[1]:= eq1= Sin[x] == x;
>
>Is there a way to get just the left-hand side or right-hand side of the
>equation? Something like:
>
> In[2]:= LHS[eq1]
> Out[2]:= Sin[x]
>

David,

eq1= Sin[x] == x;

You can use Part to extract the LHS or RHS.

eq1[[1]]

Sin[x]

First[eq1]

Sin[x]

eq1[[2]]

x

Last[eq1]

x

For more complex expressions, you can use Part to extract any specific part

eqn2 = a*x^2 + b*x + c == 0;

eqn2[[1]]

c + b*x + a*x^2

Table[eqn2[[1,k]], {k, 3}]

{c, b*x, a*x^2}

Table[eqn2[[1,3, k]], {k, 2}]

{a, x^2}

Table[eqn2[[1,3, 2, k]], {k, 2}]

{x, 2}

Bob Hanlon


0 new messages