Advertisement
Guest User

DET

a guest
Sep 17th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Eiffel 2.72 KB | None | 0 0
  1. note
  2.     description: "ALI application root class"
  3.     date: "$Date$"
  4.     revision: "$Revision$"
  5.  
  6. class
  7.     APPLICATION
  8.  
  9. inherit
  10.     ARGUMENTS_32
  11.  
  12. create
  13.     make
  14.  
  15. feature {NONE} -- Initialization
  16.  
  17.     make
  18.         local
  19.             matrix : ARRAY [ARRAY[INTEGER]]
  20.             arr: ARRAY[INTEGER]
  21.             i: INTEGER
  22.             j: INTEGER
  23.             -- Run application.
  24.         do
  25.             --create matrix.make_filled ( create {ARRAY[INTEGER]}.make_filled (1, 1, 3) , 1, 3)
  26.             create matrix.make_empty
  27.             from i:=1 until i>3 loop
  28.                 create arr.make_empty
  29.                 from j:=1 until j>3 loop
  30.                     arr.force (1 ,j)
  31.                     j:= j+1
  32.                 end
  33.                 matrix.force (arr, i)
  34.                 i:= i + 1
  35.             end
  36.             matrix[1][1]:= 5
  37.             matrix[2][2]:= 3
  38.             print (det(matrix))
  39.         end
  40.     det(m: ARRAY[ARRAY[INTEGER]]): INTEGER
  41.             require
  42.                 condition: m.count=(m[1].count)
  43.             local
  44.                 i: INTEGER
  45.                 j: INTEGER
  46.                 k: INTEGER
  47.                 l: INTEGER
  48.                 a: INTEGER
  49.                 n: INTEGER
  50.                 m3: ARRAY[ARRAY[INTEGER]]
  51.             do
  52.                 n:= m.count
  53.                 if n=1 then
  54.                     a:=m[1][1]
  55.                     print (m.count.out+"%N")
  56.                 else
  57.                     a:=0
  58.                     print (m.count.out+"%N")
  59.                     create m3.make_empty
  60.                     from i:=1 until i>n-1 loop
  61.                         m3.force( create {ARRAY[INTEGER]}.make_filled (0, 1, n-1), i)
  62.                         i:=i+1
  63.                     end
  64.                     from j:=1 until j>n loop
  65.  
  66.                         from k:=1 until k>n-1 loop
  67.                             from l:=1 until l>j-1 loop
  68.                                 m3[k][l]:=m[k+1][l]
  69.                                 l:=l+1
  70.                                 --print (m3.count.out + "%N")
  71.                             end
  72.                             k:=k+1
  73.                         end
  74.                         from k:=1 until k>n-1 loop
  75.                             from l:=j until l>n-1 loop
  76.                                 m3[k][l]:=m[k+1][l+1]
  77.                                 l:=l+1
  78.                                 --print (m3.count.out + "%N")
  79.                             end
  80.                             k:=k+1
  81.                         end
  82.                         if m.count = 2 then
  83.                             print ( "%N" + m[1][1].out + m[1][2].out + m[2][1].out + m[2][2].out + "%N"  )
  84.                         end
  85.                         if j\\2=1 then
  86.                             a:= a+m[1][j]*det(m3)
  87.                         else
  88.                             a:=a-m[1][j]*det(m3)
  89.                         end
  90.                         j:=j+1
  91.                     end
  92.                 end
  93.                 Result:=a
  94.             end
  95.  
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement