Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- note
- description: "ALI application root class"
- date: "$Date$"
- revision: "$Revision$"
- class
- APPLICATION
- inherit
- ARGUMENTS_32
- create
- make
- feature {NONE} -- Initialization
- make
- local
- matrix : ARRAY [ARRAY[INTEGER]]
- arr: ARRAY[INTEGER]
- i: INTEGER
- j: INTEGER
- -- Run application.
- do
- --create matrix.make_filled ( create {ARRAY[INTEGER]}.make_filled (1, 1, 3) , 1, 3)
- create matrix.make_empty
- from i:=1 until i>3 loop
- create arr.make_empty
- from j:=1 until j>3 loop
- arr.force (1 ,j)
- j:= j+1
- end
- matrix.force (arr, i)
- i:= i + 1
- end
- matrix[1][1]:= 5
- matrix[2][2]:= 3
- print (det(matrix))
- end
- det(m: ARRAY[ARRAY[INTEGER]]): INTEGER
- require
- condition: m.count=(m[1].count)
- local
- i: INTEGER
- j: INTEGER
- k: INTEGER
- l: INTEGER
- a: INTEGER
- n: INTEGER
- m3: ARRAY[ARRAY[INTEGER]]
- do
- n:= m.count
- if n=1 then
- a:=m[1][1]
- print (m.count.out+"%N")
- else
- a:=0
- print (m.count.out+"%N")
- create m3.make_empty
- from i:=1 until i>n-1 loop
- m3.force( create {ARRAY[INTEGER]}.make_filled (0, 1, n-1), i)
- i:=i+1
- end
- from j:=1 until j>n loop
- from k:=1 until k>n-1 loop
- from l:=1 until l>j-1 loop
- m3[k][l]:=m[k+1][l]
- l:=l+1
- --print (m3.count.out + "%N")
- end
- k:=k+1
- end
- from k:=1 until k>n-1 loop
- from l:=j until l>n-1 loop
- m3[k][l]:=m[k+1][l+1]
- l:=l+1
- --print (m3.count.out + "%N")
- end
- k:=k+1
- end
- if m.count = 2 then
- print ( "%N" + m[1][1].out + m[1][2].out + m[2][1].out + m[2][2].out + "%N" )
- end
- if j\\2=1 then
- a:= a+m[1][j]*det(m3)
- else
- a:=a-m[1][j]*det(m3)
- end
- j:=j+1
- end
- end
- Result:=a
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement