kloop
kloop

Reputation: 4721

How do I take derivatives in Wolfram Mathematica?

I am trying to learn a little bit about Wolfram Mathematica.

I want to define a symbolic function

f(x)=h(C*g(Ax+b)+d)

where x is a vector, g is a function that takes a vector and returns a vector and h is a function that takes a vector and returns a scalar.

I don't want to commit to specific g and h, I just want to have a symbolic representation for them.

I would like to get a symbolic form for the third order derivatives (which would be a tensor) -- is there a way to do that in Wolfram Mathematica?

EDIT: I should mention, A and C are matrices, and b and d are vectors.

Here is what I tried and didn't work:

enter image description here

Upvotes: 1

Views: 1621

Answers (2)

Chris Degnen
Chris Degnen

Reputation: 8655

Three methods of notation, all producing the same result.

f[x_] := Sin[x] + x^2

D[f[x], x]

2 x + Cos[x]

f'[x]

2 x + Cos[x]

f''[x]

2 - Sin[x]

using an alternative form of definition of f

Clear[f]

f = Sin[x] + x^2

D[f, x]

2 x + Cos[x]

δx f

2 x + Cos[x]

δ{x,2} f

2 - Sin[x]

Note

δ{x,2} f is supposed to be the subscript form of D[f, {x, 2}] but web formatting is limited.

Scoping out matrix and vector dimensions, and using S instead of C since the latter is a protected (uppercase) symbol.

A = {{1, 2, 3}, {4, 5, 6}};
x = {2, 4, 8};
A.x

{34, 76}

b = {3, 5};
h = 3;
h (A.x + b)

{111, 243}

S = {{1, 2}, {3, 4}, {5, 6}};
S.(h (A.x + b))

{597, 1305, 2013}

d = {2, 4, 8};
g = 2;
g (S.(h (A.x + b)) + d)

{1198, 2618, 4042}

So compatible matrix and vector assumptions can be made. (It turns out the derivative result comes out the same without taking the trouble to make the assumptions.)

Clear[A, x, b, S, d]

$Assumptions = {
  Element[A, Matrices[{m, n}]],
  Element[x, Vectors[n]],
  Element[b, Vectors[m]],
  Element[S, Matrices[{n, m}]],
  Element[d, Vectors[n]]};

f = g (S.(h (A.x + b)) + d);

D[f, x]

g S.(h A.1)

D[f, {x, 3}]

0

I'm not sure if these results are correct so if you find out do comment.

Upvotes: 0

Bill
Bill

Reputation: 3977

Try this

f[x_] := x*E^x

and then this

f'[x]

returns this

E^x + E^x x

and this

f''[x]

returns this

2 E^x + E^x x

Upvotes: 2

Related Questions