One thing to watch out for in cases like this is the old extended precision 
80-bit floating point format. Scilab 5 doesn't use it, but the Fortan program 
might do I guess. Scilab 4 used it too, and when I switched from version 4 to 5 
some numerical results related to resonant filters changed in my setup.

Cheers,
Arvid

Get Outlook for iOS<https://aka.ms/o0ukef>

________________________________
From: users <[email protected]> on behalf of Paul Bignier 
<[email protected]>
Sent: Monday, August 22, 2016 9:06:50 AM
To: Users mailing list for Scilab
Subject: Re: [Scilab-users] Numerical precision



Hello Claus,

If I get this right, after finding discrepancies between Scilab & Fortran, you 
identified the origin of the problem: the input was different.

So you fed Scilab the same input you had in Fortran and got equal results, so 
no problem so far.

Have you tried feeding Fortran the Scilab input? See if it gives the same 
results as Scilab.

As for the input/output variation, it's not that surprising to me if your 
system is poorly conditioned, especially at some points of interest (near the 
resonance frequency).

Best regards,

Paul

On 08/21/2016 06:51 PM, Claus Futtrup wrote:
Hi there

OK, so I went ahead and took some Fortran input ... yes, I do get the same 
output as Fortran, so it seems there's no calculation error per se in Scilab. 
It's just tiny differences in the input which generate large differences in 
output. It's scary.

If you compare the input (dz1 in scilab vs. dz1 in fortran, you get differences 
of around :

1->dz1s./dz1f
 ans  =

    0.9998331 + 0.0000339i
    0.9998132 + 0.0000391i
    0.9998197 + 0.0000391i


And if you compare input for dz2, you get similar tiny differences :

-1->dz2s./dz2f
 ans  =

    0.9999629 + 0.0000126i
    0.9999600 + 0.0000145i
    0.9999635 + 0.0000145i

The difference in magnitude is on the scale of less than 0.02%.

Here's a complete script, including comments which shows the results and 
explains. I only include the three datapoints around fs, which are of interest:


// dz_test.sce

// Scilab input/output for zm_star:

    dz1s = [-0.503483777422459-0.5757953650438843*%i
-0.5114164682962974-0.5883274915921053*%i
-0.5189524114871444-0.6013228498050527*%i]

    dz2s = [-0.9956247120533783-1.1585555511721832*%i
-1.019729681961281-1.1864195137402458*%i
-1.0436439978573127-1.2149095747738672*%i]

    mu = 1.997015667744342;

    zm_star = (1-mu)* dz1s .* dz2s ./ (dz2s-mu*dz1s);

// =
//    67.582546 - 57.549843i
//    104.56363 + 0.9610187i
//    64.846465 + 47.016802i

// Fortran input:

    dz1f = [-0.50358736782056468-0.57587442109900699*%i
-0.51153502148422891-0.58841744553307240*%i
-0.51906952093260994-0.60141095056474114*%i]

    dz2f = [-0.99567617243878548-1.1585859673221321*%i
-1.0197876382178386-1.1864521484345998*%i
-1.0436997434456954-1.2149387979780446*%i]

    zm_star = (1-mu)* dz1f .* dz2f ./ (dz2f-mu*dz1f);

// Scilab output:

// =
//    66.547108 - 58.427427i
//    105.67638 - 0.8443203i
//    66.018415 + 47.279403i

// Fortran output:
// (  66.547108467527437     , -58.427426595183157     )
// (  105.67638116311093     ,-0.84432029182632362     )
// (  66.018415098214774     ,  47.279402998470466     )

As can be seen. Scilab gives the same output as Fortran, when the input is the 
same.

I'm just totally surprised how such small differences in input can generate 
such large differences in output.

Best regards,
Claus

On 21-08-2016 16:11, Claus Futtrup wrote:

Dear Scilab Users

I have a script, which imitates a Fortran script. I can see there's a 
difference in calculation of about 1%, which is very strange to me. Input 
parameters (dz1 and dz2 vectors, length 1200) to the equation seem to agree 
within 0,1% ... so right now my theory is that the precision slips away when I 
do the following calculation:

Scilab: zm_star = (1-mu)* dz1 .* dz2 ./ (dz2-mu*dz1); // model free mech. 
impedance

Fortran: zm_star = (1-mu)*dz1*dz2/(dz2-mu*dz1)

Do you see anything in the Scilab formulation, which should worry me / which 
would give me such a high error?

P.S. mu is a mass-ratio = 1.9970156677443420... and it's exactly the same value 
in both Scilab and Fortran.

Most of the calculations in the output vector are OK, but in particular around 
the resonance frequency, I can list the following three datapoints 
(zm_star(47:49)), to show what is worrying me:

In Fortran, data no. 47-48-49 (near fs):

 (  66.547108467527437     , -58.427426595183157     )
 (  105.67638116311093     ,-0.84432029182632362     )
 (  66.018415098214774     ,  47.279402998470466     )

Whereas in Scilab I get:

67.58254632254881 - 57.549843258298814*%i
104.56362768103634 + 0.9610187273575014*%i
64.84646498264745 + 47.01680213507681*%i

In particular the imaginary part is different at the middle data point (near 
fs) where from Fortran the value is negative, whereas in Scilab the value is 
positive. It seems that the calculation of zm_star involves some math 
operations that could be critical to the precision.

If you study the impedance magnitude (pythagoras...), the results from Fortran 
are about 1% higher in value - IMHO that's non-negligible.

Studying the Nyquist circle plot of the data, it seems to me that in general 
the Fortran calculation is more correct.

What is going wrong with the Scilab equation? Please let me know if you have 
any ideas how to increase the precision of the calculation. Thanks.

P.S. I'm using Scilab 5.5.0 (64 bit, Windows 10). Could it be the Intel Math 
Kernel that's doing this wrong?

/Claus




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



--
Paul BIGNIER
Development engineer
-----------------------------------------------------------
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles, France
Phone: +33.1.80.77.04.68
http://www.scilab-enterprises.com
_______________________________________________
users mailing list
[email protected]
http://lists.scilab.org/mailman/listinfo/users

Reply via email to