From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, T_TVD_MIME_NO_HEADERS autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c1bdceb867926fdb X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Interfacing Ada with C Date: Thu, 05 Aug 2010 21:25:29 +0100 Organization: A noiseless patient Spider Message-ID: References: <0ee9eec7-6024-4fb8-8df0-f65c146e4b84@i28g2000yqa.googlegroups.com> <143ef70b-7e74-426b-a621-a5fd157849be@x21g2000yqa.googlegroups.com> <06eb8f61-2a0c-4dda-93f3-8414d32b6e4f@f20g2000pro.googlegroups.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Date: Thu, 5 Aug 2010 20:25:30 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="KCXegvZb5vh43D+f3BR6Ew"; logging-data="30318"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX188TIVHMcGNb3DPjrw9TEE9CrhRRcCC6mY=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (darwin) Cancel-Lock: sha1:lXwHW4nSNf+p9wBHFtbQDHnvK30= sha1:/yTqDfpvzwVdPs7F2dvj9I3JCAQ= Xref: g2news1.google.com comp.lang.ada:12888 Date: 2010-08-05T21:25:29+01:00 List-Id: --=-=-= Jeffrey Carter writes: > On 08/05/2010 10:24 AM, Ada novice wrote: >> >> They are much more accurate and better results of course. I wonder why >> Matlab tends to be give very "accurate" answers. Normally 15 digits of >> precision is also used there. > > You requested 15 decimal digits; your results are zero to 15 decimal > places. If you output in non-scientific notation you'd get zero; > presumably that's what Matlab is doing. The attached update uses fixed notation, looks rather better. Note that the reason for the lack of precision in the Test16 results is likely because the inputs are only specified to 6 digits. --=-=-= Content-Disposition: inline; filename=test_extensions.adb Content-Description: New test program -- This package is free software; you can redistribute it and/or -- modify it under terms of the GNU General Public License as -- published by the Free Software Foundation; either version 3, or -- (at your option) any later version. It is distributed in the -- hope that it will be useful, but WITHOUT ANY WARRANTY; without -- even the implied warranty of MERCHANTABILITY or FITNESS FOR A -- PARTICULAR PURPOSE. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING3. If not, see -- . -- -- Copyright Simon Wright with Ada.Text_IO; use Ada.Text_IO; with Ada.Numerics.Generic_Real_Arrays; with Ada.Numerics.Generic_Complex_Types; with Ada.Numerics.Generic_Complex_Arrays.Extensions; procedure Test_Extensions is subtype My_Float is Long_Float; package My_Float_IO is new Float_IO (My_Float); use My_Float_IO; package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (My_Float); package Complex_Types is new Ada.Numerics.Generic_Complex_Types (My_Float); package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays (Real_Arrays, Complex_Types); package Extensions is new Complex_Arrays.Extensions; use Real_Arrays; use Complex_Types; use Complex_Arrays; begin declare -- Values in yc's example Input : constant Complex_Matrix := (((8.0, 0.0), (-1.0, 0.0), (-5.0, 0.0)), ((-4.0, 0.0), (4.0, 0.0), (-2.0, 0.0)), ((18.0, 0.0), (-5.0, 0.0), (-7.0, 0.0))); Result : Complex_Vector (1 .. Input'Length (1)); begin Put_Line ("Values from <143ef70b-7e74-426b-a621-a5fd157849be" & "@x21g2000yqa.googlegroups.com>"); Result := Extensions.Eigenvalues (Input); for J in Result'Range loop Put (Result (J).Re, Exp => 0); Put (" "); Put (Result (J).Im, Exp => 0); New_Line; end loop; New_Line; end; declare -- Values in Test 16 of -- http://people.sc.fsu.edu/~jburkardt/f_src/lapack/lapack_OSX_prb_output.txt Z : constant Complex := (0.0, 0.0); A : constant Complex := (2.44949, 0.0); B : constant Complex := (3.16228, 0.0); C : constant Complex := (3.46410, 0.0); Input : constant Complex_Matrix := ( 1 => (Z, A, Z, Z, Z, Z, Z), 2 => (A, Z, B, Z, Z, Z, Z), 3 => (Z, B, Z, C, Z, Z, Z), 4 => (Z, Z, C, Z, C, Z, Z), 5 => (Z, Z, Z, C, Z, B, Z), 6 => (Z, Z, Z, Z, B, Z, A), 7 => (Z, Z, Z, Z, Z, A, Z) ); begin Put_Line ("Values in Test16 of " & "http://people.sc.fsu.edu/~jburkardt/f_src/lapack" & "/lapack_OSX_prb_output.txt"); -- GNAT: Eigenvalues of symmetrix complex matrix are real Put_Line ("using Complex_Arrays.Eigenvalues"); declare Result : constant Real_Vector := Complex_Arrays.Eigenvalues (Input); begin for J in Result'Range loop Put (Result (J), Exp => 0); New_Line; end loop; end; New_Line; -- Extension: Eigenvalues of general complex matrix are complex. Put_Line ("using Extensions.Eigenvalues"); declare Result : constant Complex_Vector := Extensions.Eigenvalues (Input); begin for J in Result'Range loop Put (Result (J).Re, Exp => 0); Put (" "); Put (Result (J).Im, Exp => 0); New_Line; end loop; end; New_Line; end; declare -- Values from http://en.wikipedia.org/wiki/Skew-symmetric_matrix Input : constant Complex_Matrix := (((0.0, 0.0), (2.0, 0.0), (-1.0, 0.0)), ((-2.0, 0.0), (0.0, 0.0), (-4.0, 0.0)), ((1.0, 0.0), (4.0, 0.0), (0.0, 0.0))); Result : Complex_Vector (1 .. Input'Length (1)); begin Put_Line ("Values from http://en.wikipedia.org/wiki/Skew-symmetric_matrix"); Result := Extensions.Eigenvalues (Input); for J in Result'Range loop Put (Result (J).Re, Exp => 0); Put (" "); Put (Result (J).Im, Exp => 0); New_Line; end loop; New_Line; end; declare -- Values from http://en.wikipedia.org/wiki/Orthogonal_matrix Input : constant Complex_Matrix := (((0.0, 0.0), (-0.8, 0.0), (-0.6, 0.0)), ((0.8, 0.0), (-0.36, 0.0), (0.48, 0.0)), ((0.6, 0.0), (0.48, 0.0), (-0.64, 0.0))); Result : Complex_Vector (1 .. Input'Length (1)); begin Put_Line ("Values from http://en.wikipedia.org/wiki/Orthogonal_matrix"); Result := Extensions.Eigenvalues (Input); for J in Result'Range loop Put (Result (J).Re, Exp => 0); Put (" "); Put (Result (J).Im, Exp => 0); New_Line; end loop; New_Line; end; end Test_Extensions; --=-=-=--