How to compute this chain rule process for higher derivative using a software

69 Views Asked by At

Consider the following system: $$ \begin{align} \dot{x}_1 &= -x^3_1 + 2x^3_2 \tag{1} \\ \dot{x}_2 &= -2x_1x^2_2 \tag{2} \end{align} $$ The Lyapunov function and its first derivative are $$ \begin{align} V(x) &= \frac{1}{2}x^2_1 + \frac{1}{2}x^2_2 \tag{3} \\ \dot{V}(x) &= -x^4_1 \tag{4} \end{align} $$ Don't worry about how $\dot{V}(x)$ is obtained. Now I need to compute the second derivative of $V(x)$ which is: $$ \begin{align} \ddot{V}(x) &= -4x^3_1\dot{x}_1 \tag{5} \end{align} $$ From Eq(1)(5), we get: $$ \begin{align} \ddot{V}(x) &= -4x^3_1\dot{x}_1 \\ &= -4x^3_1(-x^3_1 + 2x^3_2) \\ &= 4x^6_1 - 8x^3_1x^3_2 \tag{6} \end{align} $$ Now to get the third derivative, we can do: $$ \begin{align} \dddot{V}(x) &= 24x^5_1\dot{x}_1 - 8\Big[3x^2_1\dot{x}_1x^3_2 + 3x^3_1x^2_2\dot{x}_2 \Big] \end{align} $$ The process goes in this manner until $x_2$ isolated. Is there any program which can do this tedious calculation for higher derivatives? Matlab is welcome since I have an access to it. Other online softwares are welcome as well as long as they are free.

2

There are 2 best solutions below

2
On BEST ANSWER

Wolfram Cloud will help you with this

First define the system of equations

Clear[t,x1,x2];
dx1 = -x1[t]^3 + 2x2[t]^3;
dx2 = -2x1[t]x2[t]^2;

V=x1[t]^2/2 + x2[t]^2/2;

And now build the recursive list

nmax = 2
NestList[(D[#,t]/.{x1'[t] -> dx1, x2'[t] -> dx2}//FullSimplify)&, V, nmax]

This will give you a list of the form

$$ \{V, V^{(1)}, \cdots, V^{(n_\max)} \} $$

where $V^{(k)} = {\rm d}^k V/{\rm d} t^k$

enter image description here

which is exactly what you have in your post. Change the value of nmax to change the number of iterations

0
On

In Matlab, you define a vector of variables and a vector of right-hand sides, say,

x = [x1; x2];
f= [-x1^3+2*x2^3;−2*x1*x2^2];

and compute the derivative of $V(x_1,x_2)$ w.r.t. $f$ iteratively:

D1V=jacobian(V,x)*f;
D2V=jacobian(D1V,x)*f;

etc. You can use Matlab's simplify if the expressions become very bulky.