MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to use the result of Solve in Plot?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111649] Re: How to use the result of Solve in Plot?
  • From: Helen Read <hpr at together.net>
  • Date: Mon, 9 Aug 2010 05:12:23 -0400 (EDT)
  • References: <i3m3sv$hi4$1@smc.vnet.net>
  • Reply-to: HPR <read at math.uvm.edu>

On 8/8/2010 7:19 AM, Eduardo M. A. M.Mendes wrote:
> Hello
>
> I want to use the result of Solve[{5*x+4*y==12},{y}] in Plot[.,{x,0,2}].
> Plot[Solve[.],{x,0,2}] does not work.

The results of Solve are given as a list of replacement rules. For 
example, try the following.

Solve[14 x^2 - 17 x - 6 == 0, x]


The output looks like this:

{{x -> -(2/7)}, {x -> 3/2}}

This is a list of replacement rules, {x->-2/7} and {x->3/2}

Here is how we evaluate x according to a replacement rule.

x/.{x->-2/7}

x/.{x->3/2}

So to get the solutions out of Solve, we do this.

x /. Solve[14 x^2 - 17 x - 6 == 0, x]

You might want to name them when you do it.

solns=x /. Solve[14 x^2 - 17 x - 6 == 0, x]

Try putting solns in a new cell and evaluate. See?

You can also pick out the solutions individually, like this.


a=x /. Solve[14 x^2 - 17 x - 6 == 0, x][[1]]


b=x /. Solve[14 x^2 - 17 x - 6 == 0, x][[2]]


Plot[14x^2-17x-6,{x,a,b}]


Now, go back to your example. For starters, you don't need all those 
curly braces, since you have only one equation and one variable to solve 
for. (If you have a list of equations to solve simultaneously, and a 
list of variables to solve for, enclose the list of equations and the 
list of variables in curly braces.)

So you can enter your equation more simply, like this.

Solve[5*x + 4*y == 12, y]

Now, the result is given in the form of a list of replacement rules. You 
want to evaluate y according to the replacement rule given by the first 
solution (which in the example is the only solution). Since the result 
is a function, rather than naming it the way we did in the previous 
example, let's define the solution as a function of x.

f[x_] = y /. Solve[5*x + 4*y == 12, y][[1]]


Plot[f[x], {x, 0, 2}]


-- 
Helen Read
University of Vermont


  • Prev by Date: Re: A new graphic user interface
  • Next by Date: Re: A new graphic user interface
  • Previous by thread: Re: How to use the result of Solve in Plot?
  • Next by thread: Re: How to use the result of Solve in Plot?