Hi Christophe

Thanks for the tip on inverting instead of division, I didn't know. Interesting.

In my case size(x) = [1 10000] ... (circa) ... but it calculates quickly (and only once).

My implementation of the first order Struve function is based on approximation.

I was wondering if there's anybody who has made a general implementation. (?)

Following http://mathworld.wolfram.com/StruveFunction.html, using the gamma function ... maybe this would be better if coded in Fortran?

Best regards,
Claus

On 26-01-2015 11:21, Dang, Christophe wrote:
Hello,

De : Claus Futtrup
Envoyé : samedi 24 janvier 2015 19:31

    z = 2/%pi - besselj(0,x) + (16/%pi - 5) .* (sin(x)./x) ..
              + (12 - 36/%pi) * ( (1-cos(x))./(x.^2) );
A division cost much more than several multiplications (I think something like 
a 7 factor).

If you have a big amount of data (and thus a long calculation time),
you can reduce this calculation time,
but maybe at the expense of the precision if x take very high or very low 
absolute values
(overflow or underflow of x^-2),
with the following trick (not tested):

denominator = x.^(-2);
pi_inv = 1/%pi;

     z = 2*pi_inv - besselj(0,x) + ((16*pi_inv - 5) .* sin(x).*x ..
               + (12 - 36*pi_inv) *  (1-cos(x))).*denominator;

It replaces 2*size(x) divisions by 1*size(x) division and 2*size(x) 
multiplications,
which is usually less time consuming.

Forget it if size(x) is small or x reach very high or very low absolute values.

HTH

--
Christophe Dang Ngoc Chan
Mechanical calculation engineer
This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient (or have received this e-mail in error), please 
notify the sender immediately and destroy this e-mail. Any unauthorized 
copying, disclosure or distribution of the material in this e-mail is strictly 
forbidden.
_______________________________________________
users mailing list
[email protected]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[email protected]
http://lists.scilab.org/mailman/listinfo/users

Reply via email to