Re: What is the difference between z[x_]:= D[y[x],x] and z[x_]:=y'[x]?

• To: mathgroup at smc.vnet.net
• Subject: [mg27467] Re: What is the difference between z[x_]:= D[y[x],x] and z[x_]:=y'[x]?
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Tue, 27 Feb 2001 00:37:20 -0500 (EST)
• References: <97cdfc\$d6m@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```ClearAll["`*"]

Q1})
> I want to know the difference between
>   z[x_]:=D[y[x],x]  and  z[x_]:=y'[x]

This is a a problem that often hits students hard when they start
multivariable calculus..

The underlying difference is between differentiating a formula with respect
to a variable:

D[x^2 y^3, {x,2},{y,1}]

6*y^2

and differentiating a function with respect to a position,or slot.

Derivative[2,1][#1^2 #2^3&]

6*#2^2 &

%[x,y]

6*y^2

A variant of the latter is

Derivative[2,1][Function[{x,y}, x^2 y^3]]

Function[{x, y}, 6*y^2]

%[x,y]

6*y^2

Define a function, different notation,

f[x_]:= Sin[t x  ]

The following give the same result

D[f[x],x]

t*Cos[t*x]

f'[x]

t*Cos[t*x]

But the evaluation steps are very different:

D[f[x],x]
D[Sin[t x],x]
t Cos[t x]

f'[x]
Derivative[f][x]
Derivative[1][Sin[t #1]&],{1}[x] (*derivative of a pure functon for f with
respect to slot 1*)
Evaluate[D[Sin[t #1],#1]]&[x]
a Cos[a#]&[x]

The derivative of a function can be calculated independently:

f'

t*Cos[t*#1] &

%[x]

t*Cos[t*x]

If we give x  value then differences show up:

x=a;
D[f[x],x]

t*Cos[a*t]

The value of x has already been used above.
But with

f'

t*Cos[t*#1] &

the value of x has not been used.

Of course, if we find the value of this function at x, before redefining or
clearing x then this difference seems innocuous

%[x]

t*Cos[a*t]

But a more serious difference shows up with a numerical value for x

x=7;

D[f[x],x]

General::ivar: 7 is not a valid variable.

D[Sin[7*t], 7]

Whereas

f'[x]

t*Cos[7*t]

%[x]

(t*Cos[7*t])[7]

Q2)  Two routines

Clear["`*"]

(r1[t_]=93/(1+0.12*Cos[3*t]);
d1[t_]:=ArcTan[r1[t]/D[r1[t],t]];
Block[{t},u[t_]:=If[(Pi/3\[GreaterEqual]t>0),d1[t]]];)

u[0.5]

General::ivar: 0.5 is not a valid variable.

ArcTan[92.21721745103183/D[92.21721745103183, 0.5]]

Above, Mathematica stores

?d1

Global`d1

d1[t_] := ArcTan[r1[t]/D[r1[t], t]]

So that in finding u[0.5 ] it tries to differentiate with respect to the
real number 0.5

But after

(r1[t_]=93/(1+0.12*Cos[3*t]);
d1[t_]=ArcTan[r1[t]/D[r1[t],t]];
Block[{t},u[t_]:=If[(Pi/3\[GreaterEqual]t>0),d1[t]]];)

it stores

?d1

Global`d1

d1[t_] = ArcTan[2.777777777777778*(1 + 0.12*Cos[3*t])*
Csc[3*t]]

So that differentiation with respect to a 0.5  is avoided in calculating

u[0.5]

1.22872

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"liwen liwen" <gzgear at yahoo.com> wrote in message
news:97cdfc\$d6m at smc.vnet.net...
> Dear friends,
> How are you!
> I want to know the difference between z[x_]:=
> D[y[x],x] and z[x_]:=y'[x].
>
> Also,I want to why I can not find the answer for the
> u[0.5] by the following routine:
>
> (r1[t_] = 93/(1 + 0.12*Cos[3*t]);
>   d1[t_] := ArcTan[r1[t]/D[r1[t], t]];
>   Block[{t}, u[t_] := If[(Pi/3 >= t > 0), d1[t]]];
>   )
>
> u[0.5]
> General::"ivar": "\!\(0.5`\) is not a valid variable."
>
> But it is available by the following routine:
>
> (r1[t_] = 93/(1 + 0.12*Cos[3*t]);
>   d1[t_] = ArcTan[r1[t]/D[r1[t], t]];
>   Block[{t}, u[t_] := If[(Pi/3 >= t > 0), d1[t]]];
>   )
>
> u[0.5]
> 1.22872
> (* ------------------------ *)
>
>
> Bets Regards,
>
>
> Liwen  2/26/2001
>
> E-mail: gzgear at yahoo.com
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/
>

```

• Prev by Date: RE: Re: converting hex strings
• Next by Date: Re: Summation without Mathematica
• Previous by thread: Re: What is the difference between z[x_]:= D[y[x],x] and z[x_]:=y'[x]?