re: eval differential expressions

• To: mathgroup at yoda.physics.unc.edu
• Subject: re: eval differential expressions
• From: "Dr A. Hayes" <hay at leicester.ac.uk>
• Date: Mon, 20 Jun 1994 15:41:24 +0100 (BST)

```Geoff Latham <gal at melba.bby.com.au writes:

> Is there an easy way to evaluate differential expressions for various
> functions?
> For example, if I have D[f[x],x]^2+f[x] in Mma, I'd like to evaluate it for
> various functions f[x]. This can be done via naming the expression and
> then letting f[x_]=<desired fn of x> and typing the expressions name
> upon which its evaluated - but this seems awfully clumbsy!

> Any suggestions?

> Thanks.

Here are two ways:

In[1]:= op[exp_,v_:x] := D[exp,v]^2+exp
(*The v_:x makes x the default independent variable.*)

In[2]:= op[Sin[x]]
Out[2] = Cos[x]^2 + Sin[x]

In[3]:= op[Sin[t],t]
Out[3]= Cos[t]^2 + Sin[t]

And a functional variant
In[4]:= opf[f_] := (f'[#]^2 + f[#])&

In[5]:= opf[Sin][x]
Out[5]= Cos[x]^2 + Sin[x]

Allan Hayes,
hay at le.ac.uk

```

• Prev by Date: help
• Next by Date: Re: Mathematica licensing
• Previous by thread: eval differential expressions
• Next by thread: Re: eval differential expressions