![]() (I also tried the last GNAT Community Edition, but it no longer functions on my system.) What might be needed here is one's own eigensystem routine. However, I have questions about the mathematical libraries. (Another person is talking here:) I have made small corrections and tested this in 2023, and it did not work as I expected. This solution is not tested, because the available version of GNAT GPL Ada compiler (20070405-41) does not provide an implementation of the standard library. With Ada.Text_IO use Ada.Text_IO with Ada.Complex_Text_IO use Ada.Complex_Text_IO with _Types use _Types with _Arrays use _Arrays with _Arrays use _Arrays with _Elementary_Functions use _Elementary_Functions procedure Test_Matrix is function "**" ( A : Complex_Matrix Power : Complex ) return Complex_Matrix is L : Real_Vector ( A ' Range ( 1 )) X : Complex_Matrix ( A ' Range ( 1 ), A ' Range ( 2 )) R : Complex_Matrix ( A ' Range ( 1 ), A ' Range ( 2 )) RL : Complex_Vector ( A ' Range ( 1 )) begin Eigensystem ( A, L, X ) for I in L ' Range loop RL ( I ) := ( L ( I ), 0.0 ) ** Power end loop for I in R ' Range ( 1 ) loop for J in R ' Range ( 2 ) loop declare Sum : Complex := ( 0.0, 0.0 ) begin for K in RL ' Range ( 1 ) loop Sum := Sum + X ( I, K ) * RL ( K ) * X ( J, K ) end loop R ( I, J ) := Sum end end loop end loop return R end "**" procedure Put ( A : Complex_Matrix ) is begin for I in A ' Range ( 1 ) loop for J in A ' Range ( 2 ) loop Put ( A ( I, J )) end loop New_Line end loop end Put M : Complex_Matrix ( 1. ![]() ![]() The limitation to be Hermitian is not essential and comes for the limitation of the standard Ada linear algebra library. The following program implements exponentiation of a square Hermitian complex matrix by any complex power. With Ada.Text_IO use Ada.Text_IO procedure Test_Matrix is generic type Element is private Zero : Element One : Element with function "+" ( A, B : Element ) return Element is with function "*" ( A, B : Element ) return Element is with function Image ( X : Element ) return String is package Matrices is type Matrix is array ( Integer range, Integer range ) of Element function "*" ( A, B : Matrix ) return Matrix function "**" ( A : Matrix Power : Natural ) return Matrix procedure Put ( A : Matrix ) end Matrices package body Matrices is function "*" ( A, B : Matrix ) return Matrix is R : Matrix ( A ' Range ( 1 ), B ' Range ( 2 )) Sum : Element := Zero begin for I in R ' Range ( 1 ) loop for J in R ' Range ( 2 ) loop Sum := Zero for K in A ' Range ( 2 ) loop Sum := Sum + A ( I, K ) * B ( K, J ) end loop R ( I, J ) := Sum end loop end loop return R end "*" function "**" ( A : Matrix Power : Natural ) return Matrix is begin if Power = 1 then return A end if declare R : Matrix ( A ' Range ( 1 ), A ' Range ( 2 )) := ( others => ( others => Zero )) P : Matrix := A E : Natural := Power begin for I in P ' Range ( 1 ) loop - R is identity matrix R ( I, I ) := One end loop if E = 0 then return R end if loop if E mod 2 /= 0 then R := R * P end if E := E / 2 exit when E = 0 P := P * P end loop return R end end "**" procedure Put ( A : Matrix ) is begin for I in A ' Range ( 1 ) loop for J in A ' Range ( 1 ) loop Put ( Image ( A ( I, J ))) end loop New_Line end loop end Put end Matrices package Integer_Matrices is new Matrices (Integer, 0, 1, Image => Integer'Image ) use Integer_Matrices M : Matrix ( 1. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |