Re: Solve and Plot
- To: mathgroup at smc.vnet.net
- Subject: [mg6538] Re: Solve and Plot
- From: "Seth J. Chandler" <SChandler at uh.edu>
- Date: Mon, 31 Mar 1997 23:01:37 -0500 (EST)
- Organization: University of Houston Law Center
- Sender: owner-wri-mathgroup at wolfram.com
Hello
I would like to solve an equation and then plot the solution. The
command :
Plot[Solve[3x+2y-4==0,y]],{x,-5,5}]
How can i do my plot in a one line command ?
Regards.
Here's how. The Solve command returns a List, each element of which is
itself a List of Rule objects. You just need the second part of the
relevant Rule object. One way to do this would be to do something like
Solve[3x+2y-4==0,y][[1,1,2]]. It's probably more elegant, however, to
exploit the fact that Solve yields Rule expressions by using the
built-in ReplaceAll function. Thus: ReplaceAll[y,Solve[...]]. This
yields a List with a single expression, which we extract using First.
Putting it together, we now create the one liner
Plot[First[y/.Solve[3x+2y-4==0,y]],{x,-5,5}]. Et Voila.
Seth J. Chandler
University of Houston Law Center