<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Le 18/11/2017 à 22:38, Samuel Gougeon a
écrit :<br>
</div>
<blockquote cite="mid:6b82b1da-59d7-9097-0c42-c4838605eaec@free.fr"
type="cite">
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
<div class="moz-cite-prefix">Le 18/11/2017 à 22:01, Hermes a
écrit :<br>
</div>
<blockquote cite="mid:1511038879500-0.post@n3.nabble.com"
type="cite">
<pre wrap="">Hi;
The numderivative function consumes a lot of time in the calculations.
In the following script I show two options for my "odes" function
In one of them I use the numderivative function; and the calculation is
extended by 9 minutes. And in the other I use the Jacobian determinant of
the function, for each variable, obtained in wxMaxima. And the calculation
is a few, few, seconds.
I am interested in using the function with numderivative, and very similar
to how I have developed it, since it allows me to use it for systems of more
equations.</pre>
</blockquote>
<br>
Your script makes Scilab 6.0.0 crashing every time it is run =>
trials done only on 5.5.2<br>
<br>
<ul>
<li>I get <b>145 s</b> by default when numderivative() is
called as usual from its library.<br>
Without numderivative(), i get <b>1.97 s</b>.<br>
</li>
<li>After
exec(SCI+"/modules/optimization/macros/numderivative.sci",-1),
this time decreases down to <b>45 s </b>only. This is
unlikely proper to numderivative(). 5.5.2 looks to miss an
optimization. For the time being, no way to test this on
6.0.0.</li>
<li>Your script calls numderivative() ~57000 times.<br>
</li>
<li>Profiling numderivative() and its dependencies shows that
numderivative_evalf() spends a lot of time.</li>
<li>Replacing execstr(.., "errcatch") in numderivative_evalf()
with try/catch, we get<b> </b><b><span
style="color:rgb(188,143,143);"><font color="#000000">38 s</font></span></b></li>
<li><span style="color:rgb(188,143,143);"><font color="#000000">Then,
mainly, vectorizing the function to derivate in order to
accept x with N columns instead of only 1, and changing
numderivative() in order to be able to work with this new
vectorized profile, we get <b>29 s</b>.<br>
</font></span></li>
</ul>
Improving numderivative() in order to be fully able to work with
vectorized functions should be possible, but then<br>
<ul>
<li>at first sight it will be less easy to keep it able to run
with functions that are NOT vectorized (=>
back-compatibility issue)<br>
</li>
<li>The jacobian would become an hypermatrix (OK)</li>
<li>The hessian would get up to 4 dimensions</li>
</ul>
</blockquote>
<br>
This is assuming that the architecture of the current
numderivative() implementation is kept.<br>
A complete refactoring would be possible. But used for ode(), IMO
this would not save much of the time spent, since anyway ode() calls
the function for a single point.<br>
<br>
Beside the lack of vectorization, the order is not free. For
instance, order=3 needs to call numderivative() twice, for instance
with order=2 then with order=1. This limitation is a bit strange.<br>
<br>
SG<br>
<br>
</body>
</html>