Re: Help in function defination
- To: mathgroup at smc.vnet.net
- Subject: [mg122047] Re: [mg122033] Help in function defination
- From: Heike Gramberg <heike.gramberg at gmail.com>
- Date: Mon, 10 Oct 2011 05:53:53 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201110100826.EAA15303@smc.vnet.net>
When you call for example N1dx[1,10,10], all appearances of p1 in the definition of N1dx are replaced with 1 before the definition is evaluated giving D[N1[1,10,10],1] which doesn't make sense. What you want is to apply the derivative before substituting a value for p1. This can be done by using a Block[] structure, e.g. N1dx[p1_, p2_, p3] := Block[{a}, D[N1[a, p2, p3], a] /. {a -> p1}] Alternatively, you could use Derivative: N1dx[p1_, p2_, p3_] := Derivative[1, 0, 0][N1][p1, p2, p3] In both cases N1dx[1,10,10] returns -81/8. Heike. On 10 Oct 2011, at 10:26, Mohan wrote: > Hi, I have defined some functions, but when i substitute values i get > an error message, please check below. > > Definition of a basic function > In[1]:= SFn1[p_] := (1/2)*(1 - p) > > Definition of new function using the basic function > In[65]:= N1[p1_, p2_, p3_] := (SFn1[p1]*(p1))*SFn1[p2]*SFn1[p3] > > Derivative of the new function > In[68]:= N1dx[p1_, p2_, p3_] := D[N1[p1, p2, p3], p1] > > declaring function variables for the new derivative function > In[69]:= N1dx[x, y, z] > > this is the output i want. its right > Out[69]= 1/8 (1 - x) (1 - y) (1 - z) - 1/8 x (1 - y) (1 - z) > > = ************************************************************************** ************************ > If i substitute the value for the derivative function I get an error > as shown below... > please help me to find the right way to do it. > = ************************************************************************** ************************ > In[77]:= N1dx[1, 10, 10] > > During evaluation of In[77]:= General::ivar: 1 is not a valid > variable. >> > > Out[77]= \!\( > \*SubscriptBox[\(\[PartialD]\), \(1\)]0\) > > Out[69]= 1/8 (1 - x) (1 - y) (1 - z) - 1/8 x (1 - y) (1 - z) > > In[77]:= N1dx[1, 10, 10] > > During evaluation of In[77]:= General::ivar: 1 is not a valid > variable. >> > > Out[77]= \!\( > \*SubscriptBox[\(\[PartialD]\), \(1\)]0\) >
- References:
- Help in function defination
- From: Mohan <mohanbochum@googlemail.com>
- Help in function defination