Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Problem with replacement rules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91993] Re: Problem with replacement rules
  • From: magma <maderri2 at gmail.com>
  • Date: Tue, 16 Sep 2008 19:24:02 -0400 (EDT)
  • References: <ga82r6$re7$1@smc.vnet.net> <gaar52$17m$1@smc.vnet.net>

On Sep 11, 12:16 pm, Jens-Peer Kuska <ku... at informatik.uni-leipzig.de>
wrote:
> Hi,
>
> makeFunction[expr_, x_] := Module[{var},
>    var = Complement[Variables[expr], {x}];
>    Function @@ {var, x /. Solve[expr == 0, x][[1]]}
>    ]
>
> and
>
> f = makeFunction[2 + x - y^2, x];
>
> Plot[f[z], {z, -2, 2}]
>
> ??
>
> Regards
>    Jens

This code proposed by  Jens-Peer Kuska only works with polynomial
equations, because Variables only works correctly with polynomials.
For example,

makeFunction[Sin[x]-y,x]

gives as output:

Function[{y, Sin[x]}, ArcSin[y]]

which is incorrect and cannot be plotted.

A more general code is the following:

invFunction[expr_, x_, vars_List] :=
 Function @@ {vars, x /. Solve[expr == 0, x][[1]]}

where the argument x is the dependent variable and  vars_List is the
list of independent variables.

Now you have as before:
f = invFunction[2 + x - y^2, x, {y}]

Plot[f[z], {z, -2, 2}]

for your polynomial functions, but also

f = invFunction[Sin[x] - y, x, {y}]
Plot[f[z], {z, -2, 2}]

without a problem.

An example with multiple indep. variables:

f = invFunction[Sin[x] - y - z, x, {y, z}]
Plot3D[f[y, z], {y, -1, 1}, {z, -1, 1}]

hth


  • Prev by Date: Re: how to test where a list contains constant(s) or not
  • Next by Date: Re: how to test where a list contains constant(s) or not
  • Previous by thread: Re: Problem with replacement rules
  • Next by thread: Re: Problem with replacement rules