Re: Problem with user defined functions
- To: mathgroup at smc.vnet.net
- Subject: [mg37365] Re: [mg37340] Problem with user defined functions
- From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
- Date: Fri, 25 Oct 2002 02:47:07 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
There are a number of problems with what you are trying to do. I think
rather than explaining what is wrong it may be more useful to indicate
one approach that works.
You can define your function as you did originally (assuming that was
really what you wanted to do!)
test[x_] := p /. FindRoot[Sin[p] == x, {p, 1}][[1]]
Create a plot (contrary to the usual practice in such cases do not wrap
Evaluate around the function to be plotted!)
g = Plot[test[x], {x, 0, 1}]
Now create an interpolating function from the graph:
h = Interpolation[Cases[g, Line[{x__}] -> x, Infinity]]
You can now plot the derivative:
Plot[h'[t], {t, 0, 1}]
On Thursday, October 24, 2002, at 03:55 PM, Farhat Habib wrote:
> 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
>
>
>
>
Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/