Reputation: 127
Here I've written a dynamic function as:
function dAx = dynamic(t,x)
global u;
g = 9.8;
l = 0.5;
m = 0.5;
h = 2;
dx(1,1) = x(2);
dx(2,1) = g/l*sin(x(1))-h/(m*l^2)*x(2)+1/(m*l)*cos(x(1))*u(1,1);
dx(3,1) = g*lcos(x(3))-u(2,1);
A = [x(1)*x(2)+10*x(1);10*x(2)-5*x(1);x(3)]
dx = 1e-3
dAx = [(((x(1)+dx)+(x(1)-dx))*((x(2)+dx)+(x(2)-dx)))/(2*dx)+(10*(x(1)+dx)+(x(1)-dx))/(2*dx);
((10*(x(2)+dx)+(x(2)-dx))-5*((x(1)+dx)+(x(1)-dx)))/(2*dx);
((x(3)+dx)+(x(3)-dx))/(2*dx)]; % dA/dx using central derivative method computation
Here there is a matrix A (3*1)
and function out put is derivative of matrix A
related to system states.
I've tried to use central difference method.Is my derivative matrix calculation correct?
Upvotes: 0
Views: 64
Reputation: 37
@Lahidj dAx/dx
is a matrix of the size of nA
by nx
. You compute this column by column. Take the first state (eg. x(1)
). Increment and decrement it by a small value (dx)
, like 1e-3. Get the A vectors for increased and decreased values of alpha. Compute the difference between these two vectors and divide it by two times of dx
. (A_plus - A_minus)/(2*dx)
. Repeat this for the rest of the states/columns, you would get dAx/dx
.
Upvotes: 0