       # Re: Derivative via mathematica

```cai wrote:
>
> Hi,
>
> I just used mathematica for a couple of days.  I am trying to compute
> the derivative under mathematica.  Because the function is complicated,
> I like to break it down.
>
> f[t_] = (m/(1+Exp[1/t] +b)
>
> Here m and b are functions of t.
> If I directly use command D after insert m and b terms, a very
> complicated equaion is gerenated, which I do not want.
>
> What I want is if I define the values of m' and b', rewrite the f
>
> m' = p
> b' = q   // well, I dont know how to define, this is the idea
>
> f[t_, m[t], b[t]] = (m/(1+Exp[1/t] +b)
>
> then use the command D[f[t,m[t],b[t]],t] hopeful get a equation which is
> the function of t, p and q.  How to do that?
>
> A related question, I tried to use non-defined function In:= m[t_]
> Out= m[t_]
> In:= D[m[t],t]
> Out= m'[t]
> and expected D[f[t,m[t],b[t]],t] contains m'[t].  Is it possible?
>
> Basically, it is a chain derivative question, I just want it to stop
> earlier.
>
> Could somebody help?
> Thanks.
>
> ccai1@ohiou.edu
In:=
Clear["`*"]

In:=
\$Line = 0;

Wan, here are some suggestions and comments. They do not address all of
your points but I hope that they may be of help - please mail me if you
need more help.

Mathematica, of course, uses the standard results

In:=
D[a f[t]+ b g[t],t]

Out=
a f'[t] + b g'[t]

In:=
D[f[t] g[t],t]

Out=
g[t] f'[t] + f[t] g'[t]

In:=
D[1/ g[t],t]

Out=
g'[t]
-(-----)
2
g[t]

In:=
D[f[g[t]],t]

Out=
f'[g[t]] g'[t]

And we can put in values for f and g ,  f' and g' retrospectively. This
will be demonstrated in the treatment of the example below

In:=
f1[t_] = m/(1+Exp[1/t] +b)

Out=
m
------------
1/t
1 + b + E

Mathematica assumes that m and b are independent of t.

In:=
d1=D[f1[t],t]

Out=
1/t
E    m
------------------
1/t 2  2
(1 + b + E   )  t

Which is not what you want.
We can avoid this by using

In:=
f2[t_] = m[t]/(1+Exp[1/t] +b[t])

Out=
m[t]
---------------
1/t
1 + E    + b[t]

Now we get,

In:=
d2=D[f2[t],t]

Out=
1/t
E
m[t] (-(----) + b'[t])
2
t                     m'[t] -(----------------------) +
---------------
1/t        2           1/t
(1 + E    + b[t])       1 + E    + b[t]

If we  define the functions m and b

In:=
m[t_] := Sin[t]; b[t_]:= Exp[k t]

we get

In:=
d2

Out=
1/t
k t     E
(E    k - ----) Sin[t]
2
Cos[t]                   t
--------------- - ----------------------
1/t    k t           1/t    k t 2 1 + E    + E        (1 + E    + E
)

It is possible to define the derivatives of these functions but we
cannot consistently define a function ad its derivative independently
so we clear the
definitions above (there are also programming reasons for this)

In:=
Clear[m,b]

In:=
m'[t_] = Cos[t^2]; b'[t_]:= t Exp[k t];

These derivative definitiions are used

In:=
d2

Out=
1/t
E        k t
(-(----) + E    t) m[t]
2             2
Cos[t ]           t
--------------- - -----------------------
1/t                  1/t        2 1 + E    + b[t]     (1 + E    +
b[t])

but Mathematica has left m[t]; it has not integrated m'[t] to find it.
Defining derivatives can be useful but perhaps not so much here.
Incidentally the derivatives are stored under Derivative, not m and b.

In:=
??m

>From In:=
Global`m

In:=
??Derivative

>From In:=
f' represents the derivative of a function f of one argument.
Derivative[n1, n2, ... ][f] is the general form,
representing a function obtained from f by differentiating
n1 times with respect to the first argument, n2 times with
respect to the second argument, and so on.
Derivative[m][t_] = Cos[t^2]

Derivative[b][t_] := t*Exp[k*t]

This, and the notation m'[t], b'[t], leads us to the important contrast
between functions and formulas:
g' is the first derivative of the function g;  g'[t] is its value at t -
it is
the same as D[g[t],t], the derivative of the formula g[t] with respect
to the variable t.
The FullForm of g' is

In:=
FullForm[g']

Out//FullForm=
Derivative[g]

In:=
g'[t]

Out=
g'[t]

In:=
D[g[t],t]

Out=
g'[t]

Once you get into pure functions you may wish to use a different
apporoach which reduces the chance of interference between definitions.
But first, I need to clear the definitions of the derivatives.

In:=
Clear[Derivative]

In:=
f2[t]/.{ m -> Function[t, Sin[t]],
b -> Function[t, Exp[k t]]}

Out=
Sin[t]
---------------
1/t    k t
1 + E    + E

In:=
d2/.{ m ->Sin,
b -> Function[t, Exp[k t]]}

Out=
1/t
k t     E
(E    k - ----) Sin[t]
2
Cos[t]                   t
--------------- - ----------------------
1/t    k t           1/t    k t 2 1 + E    + E        (1 + E    + E
)

or, more briefly,

In:=
d2/.{ m -> Sin,b -> (Exp[k #]&)}

Out=
1/t
k t     E
(E    k - ----) Sin[t]
2
Cos[t]                   t
--------------- - ----------------------
1/t    k t           1/t    k t 2 1 + E    + E        (1 + E    + E
)

A variant of your idea for f can be implemented by

In:=
f[m_,b_]= f2[t]

Out=
m[t]
---------------
1/t
1 + E    + b[t]

In:=
D[f[ Cos, Exp[k #]&],t]

Out=
1/t
k t     E
(E    k - ----) Cos[t]
2
t                  Sin[t] -(----------------------) -
---------------
1/t    k t 2           1/t    k t
(1 + E    + E   )       1 + E    + E

You might like to look up the following in the Help Browser D
Derivative
Dt  (total derivative)

Please notice that these functions also deal with several variables. --
--
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

```

• Prev by Date: Laplace transform of nasty function?
• Next by Date: Re: Questions on MultipleListPlot
• Prev by thread: Re: Derivative via mathematica
• Next by thread: Re: Derivative via mathematica