[Scilab-users] Numderivative and integrate

ol.bond oleksiy.bond at gmail.com
Tue Dec 12 05:16:52 CET 2017


Hi,

As for differentiation, since you use the experimental data spaced at
regular intervals, you can use the concept of differentiation matrix:

function D =3D diff_matrix(t)

    k =3D size(t,'*');

    dt =3D (t(2)-t(1));

    m =3D matrix(ones(5,1)*[3:k-2],1,5*(k-4))';

    n =3D matrix([1;2;3;4;5]*ones(1,(k-4))+ones(5,1)*[0:k-5],1,5*(k-4))';

    d =3D ones((k-4),1)*[1 -8 0 8 -1];

    sp =3D sparse([m,n],d');

    sp([1 2],1:5) =3D [-25 48 -36 16 -3; -3 -10 18 -6 1];

    sp([k-1 k],(k-4):k) =3D [-1 6 -18 10 3; 3 -16 36 -48 25];

    D =3D 1/(12*dt)*sp;

endfunction

It is based on the classical five-point centred, fourth-order finite
difference approximations.

and then, the differential can be computed very fast as follows:


n =3D size(t,'*');

Numl_Gamma_derrivative =3D zeros(n,2);

Numl_Gamma_derrivative(:,1) =3D t';

 D =3D diff_matrix(t);

tic();

Numl_Gamma_derrivative(:,2) =3D
D*Signal(2,:)';//num_diff(Signal(2,:)',t(2)-t(1),1)';

Numederivative_duration =3D toc();

scf();

plot(Numl_Gamma_derrivative(:,1),Numl_Gamma_derrivative(:,2),'b')

plot(t,Acceleration_prime,'ro')

xtitle('Jerk - numerical derivation vs derivative formula','t','$\mbox{J
[m/s}^{3}\mbox{]}$');

legend('Numerical','Reference',opt=3D1);

For the integration, you should probably also rewrite the routine to
process in matrix form.

Yours.



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html



More information about the users mailing list