Re: Simple question
- To: mathgroup@smc.vnet.net
- Subject: [mg11340] Re: Simple question
- From: Allan Hayes <hay@haystack.demon.co.uk>
- Date: Fri, 6 Mar 1998 00:40:59 -0500
- References: <6dg8ro$2vh@smc.vnet.net>
Anderson Brasil da Silva wrote:
> ... I am having troubles trying to
> create a function FUNC[f,n,p] that returns the value of the n-th
> derivative of f in the point p. My main problem is that I have no idea
> about how to create a function that takes other functions as
> parameters. Besides this problem, when I use Dt[f,{x,n}] I can get the
> derivative, but I can't get the value of this in any specific point (if
> I try something like (Dt[f,{x,n}])[0] it doesn't work).
> Can somebody help me, please?
Anderson,
Some of the difficulty arises from having to distinguish between
functions and formulas. I hope that the following examples will help
1) with formulas:
You will need to retain the information as to which variable the
differention is with respect to:
In[1]:=
func1[expr_,{x_,n_},p_]:= D[expr,{x,n}]/.x->p
In[2]:=
func1[Sin[x+y],{x,3}, r]
Out[2]=
-Cos[r+y]
2) with functions
In[3]:=
func2[f_,n_, p_] = Derivative[n][f][p];
There are several ways to get a function from a formula:
2.1)
In[4]:=
func2[Sin[#+y]&,3][p]
Out[4]=
-Cos[p+y]
2.2) Here the choice of the function (dummy) variable x echos the choice
of the D-variable in 1)
In[5]:=
func2[Function[x,Sin[x+y]],3][p]
Out[5]=
-Cos[p+y]
2.3) An external definition (again the function variable must be
specified)
In[6]:=
f[x_] := Sin[x+y]
In[7]:=
func2[f,3][p]
Out[7]=
-Cos[p+y]
--
Allan Hayes
Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642