Re: Derivatives D[ ] as Functions inside Tables; Need Help!
- To: mathgroup at smc.vnet.net
- Subject: [mg13171] Re: [mg13102] Derivatives D[ ] as Functions inside Tables; Need Help!
- From: BobHanlon at aol.com
- Date: Mon, 13 Jul 1998 07:42:20 -0400
- Sender: owner-wri-mathgroup at wolfram.com
In the definition of f2 you should evaluate the derivative; otherwise
when you supply a numeric argument you are trying to take the
derivative with respect to a number.
f1[a_, x_] := a*Cos[x] + a^2*Sin[x]
f2[a_, x_] := Evaluate[D[f1[a, x], x]]
a = 2;
Table[{x, f1[a,x], f2[a,x]} // N, {x,0,4}] // TableForm
You also had a typo in the Table call (a period instead of a comma in
f2).
Bob Hanlon
In a message dated 7/7/98 7:29:59 AM, siegman at ee.stanford.edu wrote:
>I'm trying to define a function f1[a,x] and its derivative f2[a,x],
>where from my point of view x is the independent variable and "a" is
>a parameter I'll change on different runs. So I write, as a simple
>example:
>
> Remove["Global`*"]
>
> f1[a_,x_] :=a Cos[x] + a^2 Sin[x]
>
> f1[a,x]
>
> f2[a_,x_] := D[f1[a,x],x]
>
> f2[a,x]
>
> a=2
>
> f1[a,x]
>
> f2[a,x]
>
> Table[{x, f1[a,x], f2[a.x]} // N, {x,0,4}] // TableForm
>
>and everything looks fine -- except the function f2[a,x] will not
>evaluate inside the Table[ ]. I don't understand this -- help in
>understanding will be much appreciated.