MathGroup Archive 2002

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

Search the Archive

Re: Problem with user defined functions


I would use Solve instead of FindRoot, and Part[[1,1,2]] instead of
Part[[1]]. Try this:

In[1]:=
test[x_] := Solve[Sin[p] == x, p]

In[2]:=
data[x_] := D[test[x][[1,1,2]], x]

In[3]:=
Plot[Evaluate[data[x]], {x, 0, 1}];

Tomas Garza
Mexico City
----- Original Message -----
From: "Farhat Habib" <farhat at pacific.mps.ohio-state.edu>
To: mathgroup at smc.vnet.net
Subject: [mg37379] [mg37340] Problem with user defined functions


> Hello all,
>
> I am trying to evalute a function which looks like this. This is an
> analogous problem not the actual problem.
>
> test[x_] := p /. FindRoot[Sin[p] == x, {p, 1}][[1]]
> data[x_] := D[test[x], x]
> Plot[data[x], {x, 0, 1}]
>
> Now, when trying to evaluate the derivative mathematica replaces both the
> x's with the number at which it is trying to calculate the datapoint. This
> gives an error of 'xxxx is not a valid variable'. Replacing D[test[x]]
> with test'[x] doesn't help either though it results in a different set of
> errors. Is there any of way of getting around this problem?
>
> Thanks in advance,
>
> Farhat
>
>
>




  • Prev by Date: Re: To plot solutions, FindRoot as a function
  • Next by Date: Re: To plot solutions, FindRoot as a function
  • Previous by thread: Problem with user defined functions
  • Next by thread: Re: Problem with user defined functions