-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_matrix_contructors.clj
71 lines (55 loc) · 1.48 KB
/
01_matrix_contructors.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
;
; (C) Copyright 2018 Pavel Tisnovsky
;
; All rights reserved. This program and the accompanying materials
; are made available under the terms of the Eclipse Public License v1.0
; which accompanies this distribution, and is available at
; http://www.eclipse.org/legal/epl-v10.html
;
; Contributors:
; Pavel Tisnovsky
;
; -----------------------------------------------
; příklad číslo 1 - konstruktory matic
; -----------------------------------------------
(ns matrix-constructors
(:use (incanter core)))
; matice 3x3 prvky
(def M1 (matrix [[1 2 3] [4 5 6] [7 8 9]]))
; matice s jedním řádkem
(def M2 (matrix [1 2 3 4 5 6 7 8 9]))
; matice s jedním sloupcem
(def M3 (matrix [1 2 3 4 5 6 7 8 9] 1))
; matice 4x4 s nulovými prvky
(def M4 (matrix (repeat 16 0) 4))
; matice 5x5 prvků
(def M5 (matrix (range 25) 5))
; matice 5x5 se všemi prvky nastavenými na jedničku
(def M6 (matrix (repeat 25 1) 5))
(println M1)
(println M2)
(println M3)
(println M4)
(println M5)
(println M6)
; jednotkové matice
(def I0 (identity-matrix 0))
(def I1 (identity-matrix 1))
(def I2 (identity-matrix 2))
(def I3 (identity-matrix 3))
(def I4 (identity-matrix 4))
(def I5 (identity-matrix 5))
; vytištění obsahu jednotkových matic
(println I1)
(println I2)
(println I3)
(println I4)
(println I5)
; diagonální matice
(def D1 (diag [1 2 3 4]))
(def D2 (diag (range 10)))
(def D3 (diag (repeat 10 1)))
; vytištění obsahu diagonálních matic
(println D1)
(println D2)
(println D3)