Re: FindRoot and replacement rule
- To: mathgroup at smc.vnet.net
- Subject: [mg123925] Re: FindRoot and replacement rule
- From: Helen Read <readhpr at gmail.com>
- Date: Fri, 30 Dec 2011 07:08:26 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jdh68h$kjj$1@smc.vnet.net>
It's useful if you want to substitute the solutions into a function.
For example, suppose you want to find point(s) of intersection.
f[x_] := 8 x^2 - 12 x + 5
g[x_]:=26 - 10 x
{x, f[x]} /. Solve[f[x] == g[x], x]
Here's another way that I use it all the time, when I'm rigging up
functions for my calculus students (for example when we are doing area
or volume problems etc.).
Make up a function that looks nice:
f[x_] := x^4 - 2 x^3 + 5
Say I want a parabola that will intersect f[x] at let's say x=-3/2 and
x=2. I'll need another point to determine the parabola, so plot f[x] and
pick something that will make it look nice. Let's say I want the
parabola to go through (1,15).
Now I start with a generic parabola, here called gg[x]. My final
parabola will be g[x], which I get by solving for the values of a, b,
and c in gg[x] and then evaluating gg[x] using the substitution rules
from Solve.
gg[x_] := a x^2 + b x + c
g[x_] = gg[x] /.
Solve[{gg[-3/2] == f[-3/2], gg[2] == f[2], gg[1] == 15}, {a, b,
c}][[1]]
The [[1]] is picking out the first solution (there is in fact only one,
but Solve returns a list of solutions).
Helen Read
University of Vermont
On 12/29/2011 2:52 AM, SamTakoy wrote:
> Hi,
>
> Just wondering why FindRoot and other solvers return substitution
> rules rather than simply a list of solutions. What's the advantage?
>
> Thanks!
>
> Sam
>