comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Interfacing Ada with C
Date: Thu, 05 Aug 2010 21:25:29 +0100
Date: 2010-08-05T21:25:29+01:00	[thread overview]
Message-ID: <m2k4o4dcxy.fsf@pushface.org> (raw)
In-Reply-To: i3eu6a$20fd$1@adenine.netfront.net

[-- Attachment #1: Type: text/plain, Size: 666 bytes --]

Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> 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.


[-- Attachment #2: New test program --]
[-- Type: text/plain, Size: 5011 bytes --]

--  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
--  <http://www.gnu.org/licenses/>.
--
--  Copyright Simon Wright <simon@pushface.org>

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;

  reply	other threads:[~2010-08-05 20:25 UTC|newest]

Thread overview: 112+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-24 11:57 Interfacing Ada with C Ada novice
2010-07-24 12:08 ` Robert A Duff
2010-07-24 12:32   ` Ada novice
2010-07-24 14:52   ` Marco
2010-07-24 16:38 ` Simon Wright
2010-07-24 17:58   ` Ada novice
2010-07-25  8:29     ` Simon Wright
2010-07-25 12:21       ` Ada novice
2010-07-25 13:50         ` Dmitry A. Kazakov
2010-07-25 14:12           ` Ada novice
2010-07-25 14:17             ` Ada novice
2010-07-25 14:26               ` Simon Wright
2010-07-25 16:18                 ` Ada novice
2010-07-25 17:06                   ` Dmitry A. Kazakov
2010-07-25 17:42                     ` Ada novice
     [not found]                     ` <a5ba4513-ce2b-45d1-a5f4-ff1a7945b0b0@q12g2000yqj.googlegroups.com>
2010-07-25 18:26                       ` Dmitry A. Kazakov
2010-07-25 18:52                         ` Ada novice
2010-07-25 18:58                           ` Dmitry A. Kazakov
2010-07-25 19:13                             ` Ada novice
2010-07-25 19:19                               ` Dmitry A. Kazakov
2010-07-25 19:28                                 ` Ada novice
2010-07-25 20:04                                   ` Dmitry A. Kazakov
2010-07-26 13:40                                     ` Ada novice
2010-07-26 14:52                                       ` Dmitry A. Kazakov
2010-07-26 17:14                                         ` Ada novice
     [not found]                                         ` <a2da2804-c19b-44cf-9855-834c602c4520@y11g2000yqm.googlegroups.com>
2010-07-26 17:32                                           ` Dmitry A. Kazakov
2010-07-26 17:50                                             ` Ada novice
2010-07-27 12:24                                               ` Peter Hermann
2010-07-27 19:01                                                 ` Ada novice
2010-07-28  9:56                                                   ` team-ada (was e: " Peter Hermann
2010-07-27  5:50                     ` Ada novice
2010-07-27  7:27                       ` Dmitry A. Kazakov
2010-07-27  7:43                         ` Georg Bauhaus
2010-07-27 18:37                           ` Ada novice
2010-07-27 18:40                         ` Ada novice
2010-07-25 17:24                   ` Simon Wright
2010-07-25 17:47                     ` Simon Wright
2010-07-25 17:58                       ` Ada novice
2010-07-25 23:21         ` Simon Wright
2010-07-26  1:24           ` John B. Matthews
2010-07-26 14:01           ` Ada novice
2010-07-26 15:46           ` sjw
     [not found]           ` <da987804-3948-4871-ab52-4a8e95f06d44@k39g2000yqb.googlegroups.com>
2010-07-26 19:46             ` Simon Wright
2010-07-26 20:39               ` Dmitry A. Kazakov
2010-07-27  5:46                 ` Ada novice
2010-07-27  5:43               ` Ada novice
2010-07-27 17:33                 ` Simon Wright
2010-07-27 18:34                   ` Ada novice
2010-07-28 22:26               ` Simon Wright
2010-07-29  9:19                 ` Ada novice
2010-07-29 19:14                   ` Simon Wright
2010-07-29 20:25                     ` Ada novice
2010-07-30  1:46                     ` John B. Matthews
2010-07-30  9:09                       ` sjw
2010-07-30 12:41                         ` Ada novice
2010-07-30 15:13                           ` John B. Matthews
2010-07-30 17:25                             ` Ada novice
2010-07-30 19:41                               ` John B. Matthews
2010-07-30 21:08                                 ` Ada novice
2010-07-30 22:19                                   ` Simon Wright
2010-07-31 12:19                                     ` Ada novice
2010-07-31 13:25                                       ` Simon Wright
2010-07-31 19:39                                         ` Ada novice
2010-07-31 21:02                                           ` Simon Wright
2010-08-01  9:36                                             ` Ada novice
2010-08-01 16:14                                               ` Simon Wright
2010-08-01 16:27                                                 ` Ada novice
2010-08-01 17:33                                                   ` Simon Wright
     [not found]                                     ` <997036dd-ca13-4cdf-8f88-9b47a9f83b2d@s9g2000yqd.googlegroups.com>
2010-07-31 13:08                                       ` Simon Wright
2010-07-31 13:17                                         ` Simon Wright
2010-07-30 15:10                         ` John B. Matthews
2010-08-01 10:47                 ` John B. Matthews
2010-08-01 17:08                   ` Simon Wright
2010-08-02  1:08                     ` John B. Matthews
2010-08-02 16:36                       ` Simon Wright
2010-08-02 16:55                         ` Ada novice
2010-08-05  9:14                           ` Ada novice
2010-08-05 13:23                             ` John B. Matthews
2010-08-05 13:57                               ` sjw
2010-08-05 17:24                                 ` Ada novice
2010-08-05 17:59                                   ` Jeffrey Carter
2010-08-05 20:25                                     ` Simon Wright [this message]
2010-08-06  1:15                                       ` John B. Matthews
2010-08-06  9:11                                       ` Ada novice
2010-08-06  9:17                                     ` Ada novice
2010-08-06  8:04                                   ` Jacob Sparre Andersen
2010-08-06  8:42                                     ` Dmitry A. Kazakov
2010-08-06  9:26                                       ` Ada novice
2010-08-06  9:51                                         ` Dmitry A. Kazakov
2010-08-06 12:04                                           ` Ada novice
2010-08-06 16:49                                       ` Simon Wright
2010-08-06 17:27                                         ` Dmitry A. Kazakov
2010-08-06 18:15                                           ` Ada novice
2010-08-06 20:26                                           ` Simon Wright
2010-08-07  0:46                                             ` John B. Matthews
2010-08-07  7:59                                               ` Dmitry A. Kazakov
2010-08-07  9:09                                               ` Georg Bauhaus
2010-08-07 12:33                                                 ` John B. Matthews
2010-08-06  9:49                                     ` Peter Hermann
2010-08-06 12:03                                       ` Ada novice
2010-08-07  4:07                                         ` Randy Brukardt
2010-08-07  8:10                                           ` Ada novice
2010-08-06 16:41                                     ` Simon Wright
2010-08-06  8:39                                   ` sjw
2010-07-24 16:44 ` Dmitry A. Kazakov
2010-07-24 18:04   ` Ada novice
2010-07-24 19:16     ` Dmitry A. Kazakov
2010-07-25  0:22     ` tmoran
  -- strict thread matches above, loose matches on Subject: below --
2003-04-14 21:39 Paul Anderson
2003-04-14 23:05 ` tmoran
2003-04-16  2:56 ` Steve
2003-04-16  4:25   ` Steve
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox