[Scilab-users] Numderivative and integrate
Carrico, Paul
paul.carrico at esterline.com
Mon Dec 11 11:53:24 CET 2017
Dear All,
I'm wondering if there's a way to speed up the following code using both "numderivative" and "integrate" ?
I tried to replace the loops by vectors, but it fails ...
Of course this basic example has been put in place in order to test the code - I'm working with test results with more than 200 000 measurements.
Thanks for any help and/or suggestions.
Regards
Paul
###############################################################
mode(0)
clear
PATH = get_absolute_file_path("test_signal.sce");
// here we generate a sin signal just for testing
Gamma_ampl = 10; // in [g]
Frequency = 100; // in [Hz]
Omega = 2 * %pi * Frequency;
Number_of_periods = 10;
t = [0 : (1/(20 * Frequency)) : (Number_of_periods / Frequency)];
Acceleration = Gamma_ampl *sin(Omega * t);
Signal = [t ; Acceleration];
scf()
plot(t,Acceleration,'g');
xtitle('Ref curve - accelerogram','t','$\gamma \mbox{[m/s$^{2}$]}$');
xs2png(gcf(),'Accelerogram.png');
// signal first derivation : y' = (Omega * Gamma_ampl)*cos(Omega * t)
Acceleration_prime = (Omega * Gamma_ampl) * cos(Omega * t);
// calculation of the jerk -> numerical derivative
function y=Gamma_function(x)
y = interpln(Signal,x)
endfunction
n = size(t,'*');
Numl_Gamma_derrivative = zeros(2,n);
Numl_Gamma_derrivative(1,:) = t;
tic();
for i = 1 : n
Numl_Gamma_derrivative(2,i) = numderivative(Gamma_function, Numl_Gamma_derrivative(1,i),1e-3,order=4);
end
Numederivative_duration = 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=1);
xs2png(gcf(),'Jerk.png');
// calculation of the speed
Speed_ref = (Gamma_ampl / Omega) * (1 - cos(Omega * t));
Speed_num_integration = zeros(2,n);
Speed_num_integration(1,:) = t;
tic();
Speed_num_integration(2,:) = integrate('Gamma_function','x',0,t);
First_integrate_duration = toc();
scf()
plot(Speed_num_integration(1,:),Speed_num_integration(2,:),'m')
plot(t,Speed_ref,'cd')
xtitle('Speed - numerical integration vs antiderivative formula','t','v [m/s]');
legend('Numerical','Reference',opt=1);
xs2png(gcf(),'Speed.png');
// calculation of the displacement
Displ_ref = (Gamma_ampl / Omega) * (t - (sin(Omega * t)/Omega));
function y=Speed_function(x)
y = interpln(Speed_num_integration,x)
endfunction
Displ_num_integration = zeros(2,n);
Displ_num_integration(1,:) = t;
tic();
Displ_num_integration(2,:) = integrate('Speed_function','x',0,t);
Second_integrate_duration = toc();
scf()
plot(Displ_num_integration(1,:),Displ_num_integration(2,:),'r')
plot(t,Displ_ref,'b>');
xtitle('Displacement - numerical integration vs antiderivative formula','t','$\delta \mbox{ [m]}$');
legend('Numerical','Reference',opt=4);
xs2png(gcf(),'Displacements.png');
// information's
printf("The duration for Numederivative = %g\n",Numederivative_duration);
printf("The duration for 1rst integration = %g\n",First_integrate_duration);
printf("The duration for 2nd integration = %g\n",Second_integrate_duration);
EXPORT CONTROL :
Cet email ne contient pas de données techniques
This email does not contain technical data
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20171211/2060e4e3/attachment.htm>
More information about the users
mailing list