Loading [MathJax]/jax/element/mml/optable/GeneralPunctuation.js

PPPK_04

1352 days ago by fresl


Liste


Lista — uređeni skup koji sadrži određeni, konačni broj komponenata koje mogu, ali ne moraju biti istog tipa.

Komponente se navode unutar uglatih zagrada, a međusobno odvajaju zarezima:

       
[1, 2.00000000000000, 'a', 3/2, 'zadnji element']
[1, 2.00000000000000, 'a', 3/2, 'zadnji element']
       
       
[1, 2.00000000000000, 'a', 3/2, 'zadnji element']
[1, 2.00000000000000, 'a', 3/2, 'zadnji element']

Broj komponenata liste (njezinu "duljinu" — length) daje funkcija:

       
5
5

S listom se može baratati kao sa cjelinom, ali se također može pristupati i baratati pojedinim njezinim komponentama. Komponentama liste pristupa se indeksiranjem. Indeks tražene komponente navodi se unutar uglatih zagrada:

       
2.00000000000000
2.00000000000000
       
Real Field with 53 bits of precision
Real Field with 53 bits of precision
       
'a'
'a'
       
[1, 2.00000000000000, 3, 3/2, 'zadnji element']
[1, 2.00000000000000, 3, 3/2, 'zadnji element']

Ako lista sadrži n komponenata, raspon je indeksa od 0 do n1:

       
1
1
       
'zadnji element'
'zadnji element'
       
Traceback (click to the left of this block for traceback)
...
IndexError: list index out of range
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_14.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("bFs1XQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpGXGeWc/___code___.py", line 3, in <module>
    exec compile(u'l[_sage_const_5 ]
  File "", line 1, in <module>
    
IndexError: list index out of range


Pridruživanje i kopiranje lista

 

Pridruživanjem liste novoj varijabli, ta varijabla postaje samo drugi naziv iste liste:

       
       
[1, 2.00000000000000, 3, 3/2, 'zadnji element']
[1, 2.00000000000000, 3, 3/2, 'zadnji element']
       
[1, 2.00000000000000, 100, 3/2, 'zadnji element']
[1, 2.00000000000000, 100, 3/2, 'zadnji element']

... ali i

       
[1, 2.00000000000000, 100, 3/2, 'zadnji element']
[1, 2.00000000000000, 100, 3/2, 'zadnji element']

Nova se, različita lista istoga sadržaja dobiva kopiranjem:

       
[1, 2.00000000000000, 100, 3/2, 'zadnji element']
[1, 2.00000000000000, 100, 3/2, 'zadnji element']
       
[1, 2.00000000000000, 100, 3.14150000000000, 'zadnji element']
[1, 2.00000000000000, 100, 3.14150000000000, 'zadnji element']
       
[1, 2.00000000000000, 100, 3/2, 'zadnji element']
[1, 2.00000000000000, 100, 3/2, 'zadnji element']
[1, 2.00000000000000, 100, 3/2, 'zadnji element']
[1, 2.00000000000000, 100, 3/2, 'zadnji element']

 

Nizovi

 

Listu komponenata istoga tipa (npr. brojeva koji pripadaju istome skupu brojeva (Z,Q ili R)) nazvat ćemo nizom.

       
[2, 1, 4, 3, 4]
[2.00000000000000,
 1.00000000000000,
 4.00000000000000,
 3.00000000000000,
 4.00000000000000]
[4/3, 1, 2, 1/2]
[2, 1, 4, 3, 4]
[2.00000000000000,
 1.00000000000000,
 4.00000000000000,
 3.00000000000000,
 4.00000000000000]
[4/3, 1, 2, 1/2]

 

range(), srange(), xrange() & xsrange()

Funkcija srange() oblikuje rastući ili padajući niz brojeva iz ZZ, QQ, RR, RealField(m):

  • srange (end)  —  rastući niz  [zero,one,...,kone]  uz  kone<end  i  (k+1)oneend,  pri čemu su ‚zero’ i ‚one’ nula i jedan odgovarajućega tipa; ako je endzero, prazan niz;
  • srange (start, end)  —  rastući niz  [start, start+1, ..., start+k]  uz  start+k<end  i  start+(k+1)end;  ako je endstart, prazan niz;
  • srange (start, end, step)ako su  end>start  i  step>0rastući niz  [start, start+step, ..., start+kstep]  uz  start+kstep<end  start+(k+1)step endako su pak end<start  i  step<0,  padajući niz  [start, start|step|, ..., startk|step|]  uz  startk|step| > end  start(k+1)|step| end.

Dodatni (imenovani) parametri: universe, endpoint_tolerance (podrazumijeva se 1105), include_endpoint.

       
[0, 1, 2, 3, 4]
[0, 1, 2, 3, 4]
       
[0.000000000000000,
 1.00000000000000,
 2.00000000000000,
 3.00000000000000,
 4.00000000000000]
[0.000000000000000,
 1.00000000000000,
 2.00000000000000,
 3.00000000000000,
 4.00000000000000]
       
[0.000000000000000,
 1.00000000000000,
 2.00000000000000,
 3.00000000000000,
 4.00000000000000,
 5.00000000000000]
[0.000000000000000,
 1.00000000000000,
 2.00000000000000,
 3.00000000000000,
 4.00000000000000,
 5.00000000000000]
       
[0.000000000000000,
 1.00000000000000,
 2.00000000000000,
 3.00000000000000,
 4.00000000000000]
[0.000000000000000,
 1.00000000000000,
 2.00000000000000,
 3.00000000000000,
 4.00000000000000]
       
[0.000000000000000,
 1.00000000000000,
 2.00000000000000,
 3.00000000000000,
 4.00000000000000,
 5.00000000000000]
[0.000000000000000,
 1.00000000000000,
 2.00000000000000,
 3.00000000000000,
 4.00000000000000,
 5.00000000000000]
       
[2.10000000000000, 3.10000000000000, 4.10000000000000]
[2.10000000000000, 3.10000000000000, 4.10000000000000]
       
[-5.00000000000000, -4.00000000000000, -3.00000000000000]
[-5.00000000000000, -4.00000000000000, -3.00000000000000]
       
[]
[]
       
[2, 4, 6]
[2, 4, 6]
       
[2, 4, 6, 8]
[2, 4, 6, 8]
       
[2, 5/2, 3, 7/2, 4, 9/2, 5, 11/2, 6, 13/2, 7, 15/2]
[2, 5/2, 3, 7/2, 4, 9/2, 5, 11/2, 6, 13/2, 7, 15/2]
       
[7.00000000000000,
 6.50000000000000,
 6.00000000000000,
 5.50000000000000,
 5.00000000000000,
 4.50000000000000,
 4.00000000000000,
 3.50000000000000,
 3.00000000000000,
 2.50000000000000]
[7.00000000000000,
 6.50000000000000,
 6.00000000000000,
 5.50000000000000,
 5.00000000000000,
 4.50000000000000,
 4.00000000000000,
 3.50000000000000,
 3.00000000000000,
 2.50000000000000]
       
[2.10, 2.65, 3.20, 3.75, 4.30, 4.85]
[2.10, 2.65, 3.20, 3.75, 4.30, 4.85]
       
[2.10, 2.65, 3.20, 3.75, 4.30, 4.85]
[2.10, 2.65, 3.20, 3.75, 4.30, 4.85]
       
[21/10, 53/20, 16/5, 15/4, 43/10, 97/20]
[21/10, 53/20, 16/5, 15/4, 43/10, 97/20]

range() — cjelobrojni niz  (funkcija „naslijeđena” iz Pythona; bez dodatnih parametara):

       
[2, 4, 6]
[2, 4, 6]

xrange() i xsrange() — „brojači” u petljama for:

       
<generator object at 0x7fd3160ebdf8>
<generator object at 0x7fd3160ebdf8>
       
       
2
2
       
5/2
3
5/2
3
       
7/2
4
9/2
5
11/2
6
13/2
7
15/2
Traceback (click to the left of this block for traceback)
...
StopIteration
7/2
4
9/2
5
11/2
6
13/2
7
15/2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_11.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("d2hpbGUgKDEpIDoKICAgIHByaW50IHhyLm5leHQoKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmppgX2VF/___code___.py", line 3, in <module>
    exec compile(u'while (_sage_const_1 ) :\n    print xr.next()
  File "", line 2, in <module>
    
StopIteration
       
Traceback (click to the left of this block for traceback)
...
StopIteration
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_12.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("eHIubmV4dCgp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpsnqFTK/___code___.py", line 2, in <module>
    exec compile(u'xr.next()
  File "", line 1, in <module>
    
StopIteration
       
2    4
5/2    25/4
3    9
7/2    49/4
4    16
9/2    81/4
5    25
11/2    121/4
6    36
13/2    169/4
7    49
15/2    225/4
2    4
5/2    25/4
3    9
7/2    49/4
4    16
9/2    81/4
5    25
11/2    121/4
6    36
13/2    169/4
7    49
15/2    225/4
       
xrange(2, 8, 2)
xrange(2, 8, 2)
       
2    1
4    2
6    3
2    1
4    2
6    3
       
[2, 4, 6]
[2, 4, 6]
       

 

Sequence(), seq()

       
[0, 1, 2, 3, 4]
[0, 1, 2, 3, 4]
       
       
[0, 3/2, 2, 3, 4]
[0, 3/2, 2, 3, 4]
       
[0, 1, 2, 3, 4]
[0, 1, 2, 3, 4]
       
Integer Ring
Integer Ring
       
<class 'sage.structure.sequence.Sequence_generic'>
<class 'sage.structure.sequence.Sequence_generic'>
       
Traceback (click to the left of this block for traceback)
...
TypeError: no conversion of this rational to integer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_87.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("bjRbMV0gPSAzLzIKbjQ="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpO0ww7P/___code___.py", line 3, in <module>
    n4[_sage_const_1 ] = _sage_const_3 /_sage_const_2 
  File "/opt/SageMath/local/lib/python2.7/site-packages/sage/structure/sequence.py", line 500, in __setitem__
    y = self.__universe(value)
  File "sage/structure/parent.pyx", line 900, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9197)
  File "sage/rings/rational.pyx", line 4182, in sage.rings.rational.Q_to_Z._call_ (build/cythonized/sage/rings/rational.c:32210)
TypeError: no conversion of this rational to integer
       
[0, 6, 2, 3, 4]
[0, 6, 2, 3, 4]
       
[0, 1, 2, 3, 4]
[0, 1, 2, 3, 4]
       
[0, 3/2, 2, 3, 4]
[0, 3/2, 2, 3, 4]
       
[0, 3/2, 11/40, 3, 4]
[0, 3/2, 11/40, 3, 4]
       
Traceback (click to the left of this block for traceback)
...
TypeError: unable to convert pi to a rational
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_93.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("bjRbM10gPSBwaQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpW1jTun/___code___.py", line 3, in <module>
    exec compile(u'n4[_sage_const_3 ] = pi
  File "", line 1, in <module>
    
  File "/opt/SageMath/local/lib/python2.7/site-packages/sage/structure/sequence.py", line 500, in __setitem__
    y = self.__universe(value)
  File "sage/structure/parent.pyx", line 900, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9197)
  File "sage/structure/coerce_maps.pyx", line 162, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4556)
  File "sage/structure/coerce_maps.pyx", line 157, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4448)
  File "sage/rings/rational.pyx", line 531, in sage.rings.rational.Rational.__init__ (build/cythonized/sage/rings/rational.c:6395)
  File "sage/rings/rational.pyx", line 619, in sage.rings.rational.Rational.__set_value (build/cythonized/sage/rings/rational.c:7516)
  File "sage/symbolic/expression.pyx", line 1166, in sage.symbolic.expression.Expression._rational_ (build/cythonized/sage/symbolic/expression.cpp:9474)
  File "sage/rings/rational.pyx", line 531, in sage.rings.rational.Rational.__init__ (build/cythonized/sage/rings/rational.c:6395)
  File "sage/rings/rational.pyx", line 687, in sage.rings.rational.Rational.__set_value (build/cythonized/sage/rings/rational.c:8518)
TypeError: unable to convert pi to a rational
       
[0, 3/2, 11/40, 245850922/78256779, 4]
[0, 3/2, 11/40, 245850922/78256779, 4]
       
[0.000000000000000, 1.00000000000000, 2.00000000000000, 3.00000000000000,
4.00000000000000, 5.00000000000000]
[0.000000000000000, 1.00000000000000, 2.00000000000000, 3.00000000000000, 4.00000000000000, 5.00000000000000]
       
[
0.000000000000000,
1.00000000000000,
2.00000000000000,
3.00000000000000,
4.00000000000000,
5.00000000000000
]
[
0.000000000000000,
1.00000000000000,
2.00000000000000,
3.00000000000000,
4.00000000000000,
5.00000000000000
]
       
[0, 1, 2, 3, 4, 5]
[0, 1, 2, 3, 4, 5]
       
Traceback (click to the left of this block for traceback)
...
ValueError: object is immutable; please change a copy instead.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_98.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("bjVbM10gPSAxMw=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpAuSdbm/___code___.py", line 3, in <module>
    exec compile(u'n5[_sage_const_3 ] = _sage_const_13 
  File "", line 1, in <module>
    
  File "/opt/SageMath/local/lib/python2.7/site-packages/sage/structure/sequence.py", line 496, in __setitem__
    self._require_mutable()
  File "/opt/SageMath/local/lib/python2.7/site-packages/sage/structure/sequence.py", line 733, in _require_mutable
    raise ValueError("object is immutable; please change a copy instead.")
ValueError: object is immutable; please change a copy instead.


Indeksiranje, još jednom

 

       
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
       
10
10
       
10
10

Lista se može indeksirati i odostraga, indeksima od 1 do n:

       
10
10
       
1
1
       
1
1
       
Traceback (click to the left of this block for traceback)
...
IndexError: list index out of range
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_105.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("bm5bLTExXQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpEmQUfb/___code___.py", line 3, in <module>
    exec compile(u'nn[-_sage_const_11 ]
  File "", line 1, in <module>
    
IndexError: list index out of range

 

Podliste:

       
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
       
<type 'list'>
<type 'list'>
       
[3, 4, 5]
[3, 4, 5]
       
<type 'list'>
<type 'list'>
       
[3]
[3]
       
3
3
       
Integer Ring
Integer Ring
       
3
3
       
Integer Ring
Integer Ring
       
[]
[]
       
[3, 5, 7]
[3, 5, 7]
       
[9, 7, 5]
[9, 7, 5]

 

Tvorba lista i dodavanje komponenata


.append() — dodavanje komponente na kraj liste:

       
[]
1 [1]
2 [1, 4]
3 [1, 4, 9]
4 [1, 4, 9, 16]
5 [1, 4, 9, 16, 25]
[]
1 [1]
2 [1, 4]
3 [1, 4, 9]
4 [1, 4, 9, 16]
5 [1, 4, 9, 16, 25]
       
[1, 4, 9, 16, 25]
[1, 4, 9, 16, 25]


list comprehension (pokušaj opisnoga prijevoda, koji sadrži smisao: sažeta tvorba liste):

       
[1, 4, 9, 16, 25]
[1, 4, 9, 16, 25]
       
[13, 13, 13, 13, 13, 13, 13, 13, 13, 13]
[13, 13, 13, 13, 13, 13, 13, 13, 13, 13]
       
[13/7, 13/7, 13/7, 13/7, 13/7, 13/7, 13/7, 13/7, 13/7, 13/7]
[13/7, 13/7, 13/7, 13/7, 13/7, 13/7, 13/7, 13/7, 13/7, 13/7]


.extend() — dodavanje liste na kraj liste:

       
[1, 4, 9, 16, 25]
[1, 4, 9, 16, 25, 36, 49, 64]
[1, 4, 9, 16, 25]
[1, 4, 9, 16, 25, 36, 49, 64]

— umjesto funkcije .extend() može se upotrijebiti operator +=

       
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
       
10
10

— operator + oblikuju novu listu: 

       
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256]
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256]

... pritom se operandi („pribrojnici”) ne mijenjaju: 

       
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

... „zbrajanje” lista nije komutativno:

       
[121, 144, 169, 196, 225, 256, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
[121, 144, 169, 196, 225, 256, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]


.insert() — umetanje komponente u listu:

       
[1, 4, 9, 16, 25, 500, 36, 49, 64, 81, 100]
11
[1, 4, 9, 16, 25, 500, 36, 49, 64, 81, 100]
11
       
[1, 4, 9, 16, 25, 600, 36, 49, 64, 81, 100]
11
[1, 4, 9, 16, 25, 600, 36, 49, 64, 81, 100]
11
       
[1, 4, 9, 16, 25, 700, 600, 36, 49, 64, 81, 100]
12
[1, 4, 9, 16, 25, 700, 600, 36, 49, 64, 81, 100]
12
       
[1, 4, 9, 16, 25, 800, 801, 700, 600, 36, 49, 64, 81, 100]
14
[1, 4, 9, 16, 25, 800, 801, 700, 600, 36, 49, 64, 81, 100]
14
       
[1, 4, 9, 16, 25, 900, 901, 801, 700, 600, 36, 49, 64, 81, 100]
15
[1, 4, 9, 16, 25, 900, 901, 801, 700, 600, 36, 49, 64, 81, 100]
15
       
[1, 4, 9, 16, 25, 1000, 1001, 801, 700, 600, 36, 49, 64, 81, 100]
15
[1, 4, 9, 16, 25, 1000, 1001, 801, 700, 600, 36, 49, 64, 81, 100]
15


.remove() — uklanjanje komponente iz liste:

       
[1, 4, 9, 16, 25, 1000, 1001, 700, 600, 36, 49, 64, 81, 100]
14
[1, 4, 9, 16, 25, 1000, 1001, 700, 600, 36, 49, 64, 81, 100]
14


.pop() — uklanjanje komponente iz liste pomoću indeksa:

       
1000
[1, 4, 9, 16, 25, 1001, 700, 600, 36, 49, 64, 81, 100]
13
1000
[1, 4, 9, 16, 25, 1001, 700, 600, 36, 49, 64, 81, 100]
13
       
100
[1, 4, 9, 16, 25, 1001, 700, 600, 36, 49, 64, 81]
12
100
[1, 4, 9, 16, 25, 1001, 700, 600, 36, 49, 64, 81]
12
       
[]
[1, 4, 9, 16, 25, 36, 49, 64, 81]
9
[]
[1, 4, 9, 16, 25, 36, 49, 64, 81]
9


.index() — nalaženje komponente liste:

       
6
6
       
Traceback (click to the left of this block for traceback)
...
ValueError: 50 is not in list
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_171.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("bC5pbmRleCAoNTAp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpjg1MdX/___code___.py", line 3, in <module>
    exec compile(u'l.index (_sage_const_50 )
  File "", line 1, in <module>
    
ValueError: 50 is not in list


.count() — prebrojavanje komponenata liste:

       
[1, 4, 49, 9, 16, 49, 25, 36, 49, 64, 81]
[1, 4, 49, 9, 16, 49, 25, 36, 49, 64, 81]
       
3
3
       
0
0


.reverse() — „preokretanje” liste:

       
[81, 64, 49, 36, 25, 49, 16, 9, 49, 4, 1]
[81, 64, 49, 36, 25, 49, 16, 9, 49, 4, 1]
       
[81, 64, 49, 16, 25, 49, 36, 9, 49, 4, 83]
[81, 64, 49, 16, 25, 49, 36, 9, 49, 4, 83]


.sort() — sortiranje liste:

       
[4, 9, 16, 25, 36, 49, 49, 49, 64, 81, 83]
[4, 9, 16, 25, 36, 49, 49, 49, 64, 81, 83]
       
[36, 49, 9, 4, 81, 16, 64, 25, 49, 49, 83]
[36, 49, 9, 4, 81, 16, 64, 25, 49, 49, 83]
       
[4, 9, 16, 25, 36, 49, 49, 49, 64, 81, 83]
[4, 9, 16, 25, 36, 49, 49, 49, 64, 81, 83]
       
[36, 49, 9, 4, 81, 16, 64, 25, 49, 49, 83]
[36, 49, 9, 4, 81, 16, 64, 25, 49, 49, 83]

 

Elementi funkcijskoga programiranja


map()

       
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
       
[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
       
       
[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]

... neimenovane funkcije (lambda funkcije):

       
<function cube at 0x7f483e47f938>
<function cube at 0x7f483e47f938>
       
<function <lambda> at 0x7f483e47f500>
<function <lambda> at 0x7f483e47f500>
       
27
27
       
[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
       
[11, 11, 11, 11, 11, 11, 11, 11, 11, 11]
[11, 11, 11, 11, 11, 11, 11, 11, 11, 11]
       
Traceback (click to the left of this block for traceback)
...
TypeError: unsupported operand parent(s) for +: '<type 'NoneType'>' and
'Integer Ring'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_205.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("bWFwIChsYW1iZGEgeCwgeTogeCArIHksIHNyYW5nZSAoMSwgMTEpLCBzcmFuZ2UgKDExLCAwLCAtMSkp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpKGbcWH/___code___.py", line 3, in <module>
    exec compile(u'map (lambda x, y: x + y, srange (_sage_const_1 , _sage_const_11 ), srange (_sage_const_11 , _sage_const_0 , -_sage_const_1 ))
  File "", line 1, in <module>
    
  File "", line 1, in <lambda>
    
  File "sage/rings/integer.pyx", line 1792, in sage.rings.integer.Integer.__add__ (build/cythonized/sage/rings/integer.c:12197)
  File "sage/structure/coerce.pyx", line 1207, in sage.structure.coerce.CoercionModel.bin_op (build/cythonized/sage/structure/coerce.c:10896)
TypeError: unsupported operand parent(s) for +: '<type 'NoneType'>' and 'Integer Ring'
       
[-9/10, -79/9, -197/8, -339/7, -481/6, -599/5, -669/4, -667/3, -569/2, -351]
[-9/10, -79/9, -197/8, -339/7, -481/6, -599/5, -669/4, -667/3, -569/2, -351]
       
[True, False, True, False, True, False, True, False, True, False]
[True, False, True, False, True, False, True, False, True, False]


reduce()

       
5050
5050
       
5050
5050
       
5050
5050
       
5050
5050
       
5061
5061
       
5050
5050
       
2432902008176640000
2432902008176640000
       
2432902008176640000
2432902008176640000
       
-2432902008176640000
-2432902008176640000
       
0
0


filter()

       
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
       
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
       
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
       
[11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
[11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

 

usput: lambda & sort

       
       
       
[83, 81, 64, 49, 49, 49, 36, 25, 16, 9, 4]
[83, 81, 64, 49, 49, 49, 36, 25, 16, 9, 4]
       
[4, 9, 16, 25, 36, 49, 49, 49, 64, 81, 83]
[4, 9, 16, 25, 36, 49, 49, 49, 64, 81, 83]

 

Lista u listi

Komponenta liste može biti i lista:

       
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'kraj']]]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'kraj']]]
       
5
5
       
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'kraj']]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'kraj']]
       
5
5
       
1
[1, 2/3, 'a', 3/2, 'kraj']
1
[1, 2/3, 'a', 3/2, 'kraj']
       
5
5
       
1
'kraj'
1
'kraj'
       
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'kraj']]]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'kraj']]]
       
[1, 2/3, 'a', 3/2, 13]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'kraj']]]
[1, 2/3, 'a', 3/2, 13]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'kraj']]]
       
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'kraj']]]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'kraj']]]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'kraj']]]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'kraj']]]
       
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'nije kraj']]]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'nije kraj']]]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'nije kraj']]]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'nije kraj']]]
       
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'nije kraj']]]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'nije kraj']]]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'nije kraj']]]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'nije kraj']]]
       
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'nije kraj']]]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'ne, nije kraj']]]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'nije kraj']]]
[1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, [1, 2/3, 'a', 3/2, 'ne, nije kraj']]]
       
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, [11, 12, 13, 14, 15]]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, [11, 12, 13, 14, 15]]
       
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]


Vektori


Vektorinizovi brojeva na kojima su definirane određene algebarske operacije.


Zadavanje vektora


♦ Zadavanje nizom brojeva:

       
(2.00000000000000, 4.00000000000000, 2.50000000000000, -1.00000000000000,
5.00000000000000)
Vector space of dimension 5 over Real Field with 53 bits of precision
(2.00000000000000, 4.00000000000000, 2.50000000000000, -1.00000000000000, 5.00000000000000)
Vector space of dimension 5 over Real Field with 53 bits of precision
       
(0.325000000000000, 1.35000000000000, 2.37500000000000, 3.40000000000000)
Vector space of dimension 4 over Real Field with 53 bits of precision
(0.325000000000000, 1.35000000000000, 2.37500000000000, 3.40000000000000)
Vector space of dimension 4 over Real Field with 53 bits of precision
       
(-2, -3, -4, -5, -6)
Ambient free module of rank 5 over the principal ideal domain Integer Ring
(-2, -3, -4, -5, -6)
Ambient free module of rank 5 over the principal ideal domain Integer Ring

Broj komponenata vektora (njegova dimenzija ili dimenzija vektorskog prostora kojem pripada):

       
5
5
       
5
5

Zadamo li vektor listom brojeva koji (oblikom zapisa) pripadaju različitim skupovima brojeva, uzima se da svi brojevi pripadaju najsveubuhvatnijemu skupu (ZQR):

       
(2.00000000000000, 4.00000000000000, 2.50000000000000, -1.00000000000000,
5.00000000000000)
Vector space of dimension 5 over Real Field with 53 bits of precision
(2.00000000000000, 4.00000000000000, 2.50000000000000, -1.00000000000000, 5.00000000000000)
Vector space of dimension 5 over Real Field with 53 bits of precision
       
(2, 4, 5/2, -1, 5)
Vector space of dimension 5 over Rational Field
(2, 4, 5/2, -1, 5)
Vector space of dimension 5 over Rational Field

... za „realne” brojeve sveobuhvatniji znači  RealField(m)RealField(n)  ako je   m > n:

       
(0.857, 1.75, -3.14)
Vector space of dimension 3 over Real Field with 14 bits of precision
(0.857, 1.75, -3.14)
Vector space of dimension 3 over Real Field with 14 bits of precision

 

♦ Zadavanje oznakom skupa brojeva kojemu njegove komponente pripadaju (ZZ označava ZQQ označava Q, a RR označava R (s točnošću zapisa od 53 bita)) i listom komponenata:

       
(0, -5/2, 0, 17/13, 0)
(0, -5/2, 0, 17/13, 0)

Pritom se brojevi koji pripadaju drugim skupovima brojeva „pretvaraju”, ako je moguće (bez zaokruživanja ili „rezanja”), u brojeve odgovarajućega skupa:

       
(0, -5, 245850922/78256779, 7)
(0, -5, 245850922/78256779, 7)
       
(0, -5, 3, 2, 0)
(0, -5, 3, 2, 0)
       
Traceback (click to the left of this block for traceback)
...
TypeError: unable to convert 3/2 to an element of Integer Ring
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_72.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("diA9ICB2ZWN0b3IgKFpaLCBbMCwgLTUsIDMsIDYvNCwgMF0pCnY="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmplnvPcF/___code___.py", line 3, in <module>
    v =  vector (ZZ, [_sage_const_0 , -_sage_const_5 , _sage_const_3 , _sage_const_6 /_sage_const_4 , _sage_const_0 ])
  File "sage/modules/free_module_element.pyx", line 512, in sage.modules.free_module_element.vector (build/cythonized/sage/modules/free_module_element.c:5992)
  File "sage/modules/free_module_element.pyx", line 611, in sage.modules.free_module_element.prepare (build/cythonized/sage/modules/free_module_element.c:6541)
  File "/opt/SageMath/local/lib/python2.7/site-packages/sage/structure/sequence.py", line 264, in Sequence
    return Sequence_generic(x, universe, check, immutable, cr, cr_str, use_sage_types)
  File "/opt/SageMath/local/lib/python2.7/site-packages/sage/structure/sequence.py", line 452, in __init__
    .format(x[i], universe))
TypeError: unable to convert 3/2 to an element of Integer Ring
       
(0.100000000000000, 0.100000000000000, 0.100000000000000)
Vector space of dimension 3 over Real Field with 53 bits of precision
(0.100000000000000, 0.100000000000000, 0.100000000000000)
Vector space of dimension 3 over Real Field with 53 bits of precision
       
(0.100, 0.100, 0.100)
Vector space of dimension 3 over Real Field with 14 bits of precision
(0.100, 0.100, 0.100)
Vector space of dimension 3 over Real Field with 14 bits of precision

 

♦ Zadavanje oznakom skupa brojeva kojemu njegove komponente pripadaju i brojem komponenata: 

       
(0, 0, 0, 0)
(0, 0, 0, 0)

Dobiveni nul–vektor naknadno „popunjavamo”:

       
(3, -2, 1, 2)
(3, -2, 1, 2)

Nažalost, SageMath pritom dopušta lažno povećanje točnosti:

       
(0.100000000000000, 0.0999984741210938, 0.0999984741210938, 0.100000000000000)
Vector space of dimension 4 over Real Field with 53 bits of precision
(0.100000000000000, 0.0999984741210938, 0.0999984741210938, 0.100000000000000)
Vector space of dimension 4 over Real Field with 53 bits of precision

... što u nekim drugim slučajevima sprečava:

       
Traceback (click to the left of this block for traceback)
...
TypeError: cannot approximate to a precision of 53 bits, use at most 14 bits
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_88.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("TiAoUmVhbEZpZWxkKDE0KSAoMS8xMCksIDUzKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmplMIG8I/___code___.py", line 3, in <module>
    exec compile(u'N (RealField(_sage_const_14 ) (_sage_const_1 /_sage_const_10 ), _sage_const_53 )
  File "", line 1, in <module>
    
  File "/opt/SageMath/local/lib/python2.7/site-packages/sage/misc/functional.py", line 1419, in numerical_approx
    return n(prec, algorithm=algorithm)
  File "sage/structure/element.pyx", line 850, in sage.structure.element.Element.numerical_approx (build/cythonized/sage/structure/element.c:7829)
  File "sage/arith/numerical_approx.pyx", line 65, in sage.arith.numerical_approx.numerical_approx_generic (build/cythonized/sage/arith/numerical_approx.c:2666)
TypeError: cannot approximate to a precision of 53 bits, use at most 14 bits

 

♦ Vektori „popunjeni” slučajnim brojevima:

       
(-0.815298913220795, -0.726141377537976, 0.548307044581641, 0.110115482135821,
0.101082521754781)
(-0.815298913220795, -0.726141377537976, 0.548307044581641, 0.110115482135821, 0.101082521754781)
       
(2.54, -1.33, 4.76, -0.732, 5.56)
(2.54, -1.33, 4.76, -0.732, 5.56)
       
[6, 14, 16, 23, 28, 37]
[6, 14, 16, 23, 28, 37]
       
(3, 0, 6/13, 1/5, 2/17, 1/3)
(3, 0, 6/13, 1/5, 2/17, 1/3)

 

♦ „Simbolički” vektori:

       
(a0,a1,a2)
                                
                            

                                
       
Vector space of dimension 3 over Symbolic Ring
Vector space of dimension 3 over Symbolic Ring

 

Zbrajanje, oduzimanje i uspoređivanje vektora

  • ako je  c=a+b,  onda je  ci=ai+bi  za i=0,1,,n1
       
(a0+b0,a1+b1,a2+b2)
                                
                            

                                

Ako točke u ravnini ili prostoru prikažemo radijus–vektorima, onda je vektor od točke A do točke B:

       
(2, -3, 1)
(2, -3, 1)
       
True
True

 

Množenje vektora brojem

  • ako je  d=fa,  onda je  di=fai  za i=0,1,,n1
       
(a0f,a1f,a2f)
                                
                            

                                

... i posebno:

       
(a0,a1,a2)
                                
                            

                                
       
(a0,a1,a2)
                                
                            

                                
       
True
True


Duljina ili (euklidska) norma vektora

v=.

       
5
5
       
4*sqrt(3)
4*sqrt(3)
       
5.00000000000000
5.00000000000000
       
6.92820323027551
6.92820323027551
       
13
13
       
       
6.92820323027551
6.92820323027551
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
sqrt(-2)
sqrt(-2)
       
sqrt(2)
sqrt(2)
       
       
sqrt(2)
sqrt(2)
       

                                
                            

                                
       
[a0 is real, a1 is real, a2 is real]
[a0 is real, a1 is real, a2 is real]
       

                                
                            

                                

normalizacija — određivanje jediničnoga vektora na pravcu i u smislu zadanoga vektora:

       
(-4, 2, -3)
sqrt(29)
(-4, 2, -3)
sqrt(29)
       

                                
                            

                                
       
1
1
       

                                
                            

                                
       
(-4, 2, -3)
(-4, 2, -3)
       
(-4.00000000000000, 2.00000000000000, -3.00000000000000)
5.38516480713450
(-4.00000000000000, 2.00000000000000, -3.00000000000000)
5.38516480713450
       
(-0.742781352708207, 0.371390676354104, -0.557086014531156)
(-0.742781352708207, 0.371390676354104, -0.557086014531156)
       
1.00000000000000
1.00000000000000
       
(-0.742781352708207, 0.371390676354104, -0.557086014531156)
(-0.742781352708207, 0.371390676354104, -0.557086014531156)
       
(-4.00000000000000, 2.00000000000000, -3.00000000000000)
(-4.00000000000000, 2.00000000000000, -3.00000000000000)

 

Druge norme  (|v|_1, |v|_\infty)

 

       
13
13
13
13
13
13
       
19
19
       
(3/19, -12/19, 4/19)
(3/19, -12/19, 4/19)
       
13/19
13/19
       
1
1
       

                                
                            

                                
       
       

                                
                            

                                
       
12
12
       
       
12
12
       
(1/4, -1, 1/3)
(1/4, -1, 1/3)
       
1
1

 

Skalarni ili unutarnji umnožak vektora

s = \boldsymbol{\mathsf{a}}\cdot \boldsymbol{\mathsf{b}} = \boldsymbol{\mathsf{a}}^{\mathrm{T}}\, \boldsymbol{\mathsf{b}}  = \displaystyle\sum_{i=0}^{n-1}\, a_i\, b_i 

       

                                
                            

                                
       

                                
                            

                                
       
(0, 7, -17/5, 0, -2)
(1, 0, 0, 1/4, 2)
(0, 7, -17/5, 0, -2)
(1, 0, 0, 1/4, 2)
       
-4
-4
       
-4
-4
       
-4
-4
       
True
True
       
-4
-4
       

                                
                            

                                
       
       
-2
-2
       
2*I
2*I
       
2*I
2*I
       
0
0
       
2
2
       
-2*I
-2*I
       
2*I
2*I
       
4
4
       
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
-4
-4
       
-4
-4

Euklidska norma vektora za vektore iznad \mathbb{Q} i \mathbb{R}:

v = \|\boldsymbol{\mathsf{v}}\| = \sqrt{\boldsymbol{\mathsf{a}}\cdot \boldsymbol{\mathsf{a}}}

       
1/5*sqrt(1614) == 1/5*sqrt(1614)
1/5*sqrt(1614) == 1/5*sqrt(1614)
       
True
True
       
sqrt(2) == sqrt(-2)
sqrt(2) == sqrt(-2)
       
False
False
       
sqrt(2) == sqrt(2)
sqrt(2) == sqrt(2)
       
True
True
       

                                
                            

                                
       

                                
                            

                                
       
True
True

... Euklidska norma vektora za vektore iznad \mathbb{C}:

v = \|\boldsymbol{\mathsf{v}}\| = \sqrt{\boldsymbol{\mathsf{a}}\cdot \boldsymbol{\bar{\mathsf{a}}}}

 

Kut između dva vektora:  

\boldsymbol{\mathsf{a}}\cdot\boldsymbol{\mathsf{b}} = \|\boldsymbol{\mathsf{a}}\|\cdot \|\boldsymbol{\mathsf{b}}\|\cdot\cos\, (\boldsymbol{\mathsf{a}},\,\boldsymbol{\mathsf{b}}) \quad\Rightarrow\quad \cos\, (\boldsymbol{\mathsf{a}},\,\boldsymbol{\mathsf{b}}) = \dfrac{\boldsymbol{\mathsf{a}}\cdot\boldsymbol{\mathsf{b}}}{\|\boldsymbol{\mathsf{a}}\|\cdot \|\boldsymbol{\mathsf{b}}\|}

       
-40/7263*sqrt(1614)
-0.221256334039385
-40/7263*sqrt(1614)
-0.221256334039385
  • u radijanima:
       
arccos(-40/7263*sqrt(1614))
1.79389887218347
arccos(-40/7263*sqrt(1614))
1.79389887218347
  • u stupnjevima:
       
180*arccos(-40/7263*sqrt(1614))/pi
102.782834249391
180*arccos(-40/7263*sqrt(1614))/pi
102.782834249391

Međusobno okomiti vektori:

       
0
0


Vektorski umnožak vektora

\vec{c} = \vec{a}\times\vec{b} = \left| \begin{array}{ccc} \vec{\imath} & \vec{\jmath} & \vec{k} \\ a_0 & a_1 & a_2 \\ b_0 & b_1 & b_2 \end{array} \right|

       

                                
                            

                                

Vektorski je umnožak definiran samo u trodimenzionalnom (i u sedmerodimenzionalnom) prostoru, a okomit je na množenika i  na množitelja:

       
0
0
       
0
0

Posebno, ako su vektori \vec{a} i \vec{b} u ravnini xy, vector \vec{c} = \vec{a}\times\vec{b} bit će usporedan s osi z:

       

                                
                            

                                

Kolinearni vektori:

       

                                
                            

                                
       
(0, 0, 0)
(0, 0, 0)

Vektorsko množenje vektora nije komutativno:

       
       
False
False
       
True
True

 

Tenzorski ili vanjski umnožak vektora

\boldsymbol{\mathsf{A}} = \boldsymbol{\mathsf{a}}\otimes \boldsymbol{\mathsf{b}} = \boldsymbol{\mathsf{a}}\, \boldsymbol{\mathsf{b}}^{\mathrm{T}}

       

                                
                            

                                
       
       

                                
                            

                                
       
1
1
       

                                
                            

                                
       

                                
                            

                                

Tenzorsko množenje vektora nije komutativno:

\big(\boldsymbol{\mathsf{a}}\,\boldsymbol{\mathsf{b}}^{\mathrm{T}}\big)^{\mathrm{T}} \,=\, \big(\boldsymbol{\mathsf{b}}^{\mathrm{T}}\big)^{\mathrm{T}}\,\boldsymbol{\mathsf{a}}^{\mathrm{T}} \,=\, \boldsymbol{\mathsf{b}}\,\boldsymbol{\mathsf{a}}^{\mathrm{T}} \,=\, \boldsymbol{\mathsf{b}}\otimes \boldsymbol{\mathsf{a}} \qquad \Rightarrow\qquad \boldsymbol{\mathsf{b}}\otimes \boldsymbol{\mathsf{a}} \,=\, (\boldsymbol{\mathsf{a}}\otimes \boldsymbol{\mathsf{b}})^{\mathrm{T}}

 

Hadamardov ili Schurov umnožak

\boldsymbol{\mathsf{c}} = \boldsymbol{\mathsf{a}} \circ \boldsymbol{\mathsf{b}} \quad\Longleftrightarrow\quad c_i = a_i \, b_i  za i = 0, 1, \ldots, n-1

       

                                
                            

                                
       

                                
                            

                                


Matrice


Matrice — pravokutne ili kvadratne tablice redci (i stupci) kojih su nizovi brojeva i s kojima se mogu izvoditi određene algebarske operacije.


Zadavanje matrica


Matricu možemo zadati pomoću:

  • niza čije su komponente nizovi brojeva jednakih duljina:
       
Traceback (click to the left of this block for traceback)
...
ValueError: inconsistent number of columns: should be 4 but got 3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_33.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("QSA9IG1hdHJpeCAoW1sxLCAyLCAzLCA0XSwgWzUsIDYsIDddLCBbOSwgMTAsIDExLCAxMl1dKQpB"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpTgzrm9/___code___.py", line 3, in <module>
    A = matrix ([[_sage_const_1 , _sage_const_2 , _sage_const_3 , _sage_const_4 ], [_sage_const_5 , _sage_const_6 , _sage_const_7 ], [_sage_const_9 , _sage_const_10 , _sage_const_11 , _sage_const_12 ]])
  File "sage/matrix/constructor.pyx", line 625, in sage.matrix.constructor.matrix (build/cythonized/sage/matrix/constructor.c:2424)
  File "sage/matrix/args.pyx", line 652, in sage.matrix.args.MatrixArgs.matrix (build/cythonized/sage/matrix/args.c:7669)
  File "sage/matrix/args.pyx", line 915, in sage.matrix.args.MatrixArgs.finalize (build/cythonized/sage/matrix/args.c:9970)
  File "sage/matrix/args.pyx", line 1131, in sage.matrix.args.MatrixArgs.finalize_seq_seq (build/cythonized/sage/matrix/args.c:13470)
  File "sage/matrix/args.pxd", line 92, in sage.matrix.args.MatrixArgs.set_ncols (build/cythonized/sage/matrix/args.c:17117)
ValueError: inconsistent number of columns: should be 4 but got 3
       
[ 1  2  3  4]
[ 5  6  7  8]
[ 9 10 11 12]
[ 1  2  3  4]
[ 5  6  7  8]
[ 9 10 11 12]
       
Full MatrixSpace of 3 by 4 dense matrices over Integer Ring
Full MatrixSpace of 3 by 4 dense matrices over Integer Ring

... zadani nizovi tvore retke matrice;

  • broja redaka r, broja stupaca c i niza koji mora sadržavati r\times c brojeva:
       

                                
                            

                                
       
Full MatrixSpace of 4 by 3 dense matrices over Real Field with 53 bits of
precision
Full MatrixSpace of 4 by 3 dense matrices over Real Field with 53 bits of precision

... matrica se popunjava po redcima; 

... za kvadratnu je matricu dovoljno zadati broj redaka (ili broj stupaca) i niz:

       

                                
                            

                                
  • oznake skupa brojeva kojem komponente pripadaju i niza nizova koji sadrže komponente (po redcima):
       
[1.00000000000000 2.00000000000000 3.00000000000000 4.00000000000000]
[5.00000000000000 6.00000000000000 7.00000000000000 8.00000000000000]
[9.00000000000000 10.0000000000000 11.0000000000000 12.0000000000000]
[1.00000000000000 2.00000000000000 3.00000000000000 4.00000000000000]
[5.00000000000000 6.00000000000000 7.00000000000000 8.00000000000000]
[9.00000000000000 10.0000000000000 11.0000000000000 12.0000000000000]
       
Full MatrixSpace of 3 by 4 dense matrices over Real Field with 53 bits of
precision
Full MatrixSpace of 3 by 4 dense matrices over Real Field with 53 bits of precision
  • oznake skupa brojeva kojem komponente pripadaju, broja redaka i broja stupaca; time dobivamo nul–matricu koju treba kasnije „popuniti”:
       

                                
                            

                                
       

                                
                            

                                

        ... za kvadratnu matricu dovoljno je navesti broj redaka:

       
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
       
Traceback (click to the left of this block for traceback)
...
TypeError: Attempt to coerce non-integral RealNumber to Integer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_12.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("RSBbMSwgMl0gPSBSUiAocGkp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpE_fSd7/___code___.py", line 3, in <module>
    exec compile(u'E [_sage_const_1 , _sage_const_2 ] = RR (pi)
  File "", line 1, in <module>
    
  File "sage/matrix/matrix0.pyx", line 1424, in sage.matrix.matrix0.Matrix.__setitem__ (build/cythonized/sage/matrix/matrix0.c:8803)
  File "sage/matrix/matrix0.pyx", line 1529, in sage.matrix.matrix0.Matrix._coerce_element (build/cythonized/sage/matrix/matrix0.c:10280)
  File "sage/structure/parent.pyx", line 900, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9197)
  File "sage/structure/coerce_maps.pyx", line 288, in sage.structure.coerce_maps.NamedConvertMap._call_ (build/cythonized/sage/structure/coerce_maps.c:5949)
  File "sage/rings/real_mpfr.pyx", line 2177, in sage.rings.real_mpfr.RealNumber._integer_ (build/cythonized/sage/rings/real_mpfr.c:16774)
TypeError: Attempt to coerce non-integral RealNumber to Integer

 

Posebne matrice:

  • jedinična matrica:
       
[1 0 0 0 0]
[0 1 0 0 0]
[0 0 1 0 0]
[0 0 0 1 0]
[0 0 0 0 1]
[1 0 0 0 0]
[0 1 0 0 0]
[0 0 1 0 0]
[0 0 0 1 0]
[0 0 0 0 1]
       
Full MatrixSpace of 5 by 5 dense matrices over Integer Ring
Full MatrixSpace of 5 by 5 dense matrices over Integer Ring
       
[ 1.00000000000000 0.000000000000000 0.000000000000000]
[0.000000000000000  1.00000000000000 0.000000000000000]
[0.000000000000000 0.000000000000000  1.00000000000000]
[ 1.00000000000000 0.000000000000000 0.000000000000000]
[0.000000000000000  1.00000000000000 0.000000000000000]
[0.000000000000000 0.000000000000000  1.00000000000000]
       
Full MatrixSpace of 3 by 3 dense matrices over Real Field with 53 bits of
precision
Full MatrixSpace of 3 by 3 dense matrices over Real Field with 53 bits of precision
  • nul–matrica:
       
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
       
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]

... ili, manje rječito, ali i višeznačnije: 

       
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
  • dijagonalna matrica (u nizu se navode komponente na dijagonali, čime je određen broj redaka i stupaca):
       
[2/5   0   0]
[  0   3   0]
[  0   0 4/3]
[2/5   0   0]
[  0   3   0]
[  0   0 4/3]
       
Full MatrixSpace of 3 by 3 sparse matrices over Rational Field
Full MatrixSpace of 3 by 3 sparse matrices over Rational Field
  • matrica popunjena jedinicama određenoga tipa:
       
[1.00 1.00 1.00 1.00]
[1.00 1.00 1.00 1.00]
[1.00 1.00 1.00 1.00]
[1.00 1.00 1.00 1.00]
[1.00 1.00 1.00 1.00]
[1.00 1.00 1.00 1.00]
  • „slučajne” matrice:
       
[ 0.571160083873278 -0.138788964552110 -0.584569898932048]
[ 0.631718302916433  0.113700337815246  0.899398063666802]
[-0.363171469704274 0.0321498498291364  0.902404893269398]
[ 0.734574102913103 -0.725539613331700 -0.675347588359344]
[ 0.571160083873278 -0.138788964552110 -0.584569898932048]
[ 0.631718302916433  0.113700337815246  0.899398063666802]
[-0.363171469704274 0.0321498498291364  0.902404893269398]
[ 0.734574102913103 -0.725539613331700 -0.675347588359344]
       
[ 1.98450221209741  2.08772207534585  2.76450703960086]
[ 1.42346377114885  1.31261711386105  4.94299252724249]
[ 2.35023607845230  1.11683767983639 0.909040548584539]
[0.182435421725591  3.82634147734409  2.75261987567561]
[ 1.98450221209741  2.08772207534585  2.76450703960086]
[ 1.42346377114885  1.31261711386105  4.94299252724249]
[ 2.35023607845230  1.11683767983639 0.909040548584539]
[0.182435421725591  3.82634147734409  2.75261987567561]

 

Vektor kao jednoredna ili kao jednostupčana matrica:

       
(-0.435976962986311, 0.469221549690931, -0.0198113288181587)
(-0.435976962986311, 0.469221549690931, -0.0198113288181587)
       
Vector space of dimension 3 over Real Field with 53 bits of precision
Vector space of dimension 3 over Real Field with 53 bits of precision
       
[ -0.435976962986311   0.469221549690931 -0.0198113288181587]
[ -0.435976962986311   0.469221549690931 -0.0198113288181587]
       
Full MatrixSpace of 1 by 3 dense matrices over Real Field with 53 bits of
precision
Full MatrixSpace of 1 by 3 dense matrices over Real Field with 53 bits of precision
       
[ -0.435976962986311]
[  0.469221549690931]
[-0.0198113288181587]
[ -0.435976962986311]
[  0.469221549690931]
[-0.0198113288181587]
       
Full MatrixSpace of 3 by 1 dense matrices over Real Field with 53 bits of
precision
Full MatrixSpace of 3 by 1 dense matrices over Real Field with 53 bits of precision

 

Pristupanje komponentama matrice


  • pomoću para indeksa:
       
15.0000000000000
15.0000000000000
       
[11.0000000000000 12.0000000000000 13.0000000000000]
[14.0000000000000 15.0000000000000 16.0000000000000]
[17.0000000000000 18.0000000000000 19.0000000000000]
[20.0000000000000 21.0000000000000 50.0000000000000]
[11.0000000000000 12.0000000000000 13.0000000000000]
[14.0000000000000 15.0000000000000 16.0000000000000]
[17.0000000000000 18.0000000000000 19.0000000000000]
[20.0000000000000 21.0000000000000 50.0000000000000]
       
18.0000000000000
18.0000000000000
 
  • cijeli stupac ili cijeli redak matrice:
       
[11.0000000000000]
[14.0000000000000]
[17.0000000000000]
[20.0000000000000]
[11.0000000000000]
[14.0000000000000]
[17.0000000000000]
[20.0000000000000]
       
Full MatrixSpace of 4 by 1 dense matrices over Real Field with 53 bits of
precision
Full MatrixSpace of 4 by 1 dense matrices over Real Field with 53 bits of precision
       
(11.0000000000000, 14.0000000000000, 17.0000000000000, 20.0000000000000)
(11.0000000000000, 14.0000000000000, 17.0000000000000, 20.0000000000000)
       
Vector space of dimension 4 over Real Field with 53 bits of precision
Vector space of dimension 4 over Real Field with 53 bits of precision
       
[   11.0000000000000    12.0000000000000    13.0000000000000]
[   14.0000000000000    15.0000000000000    16.0000000000000]
[ -0.435976962986311   0.469221549690931 -0.0198113288181587]
[   20.0000000000000    21.0000000000000    50.0000000000000]
[   11.0000000000000    12.0000000000000    13.0000000000000]
[   14.0000000000000    15.0000000000000    16.0000000000000]
[ -0.435976962986311   0.469221549690931 -0.0198113288181587]
[   20.0000000000000    21.0000000000000    50.0000000000000]
       
Full MatrixSpace of 1 by 3 dense matrices over Real Field with 53 bits of
precision
Full MatrixSpace of 1 by 3 dense matrices over Real Field with 53 bits of precision
       
(14.0000000000000, 15.0000000000000, 16.0000000000000)
(14.0000000000000, 15.0000000000000, 16.0000000000000)
       
Vector space of dimension 3 over Real Field with 53 bits of precision
Vector space of dimension 3 over Real Field with 53 bits of precision
       
(14.0000000000000, 15.0000000000000, 16.0000000000000)
(14.0000000000000, 15.0000000000000, 16.0000000000000)
       
Vector space of dimension 3 over Real Field with 53 bits of precision
Vector space of dimension 3 over Real Field with 53 bits of precision
       
[   11.0000000000000    12.0000000000000    13.0000000000000]
[   2.35023607845230    1.11683767983639   0.909040548584539]
[ -0.435976962986311   0.469221549690931 -0.0198113288181587]
[   20.0000000000000    21.0000000000000    50.0000000000000]
[   11.0000000000000    12.0000000000000    13.0000000000000]
[   2.35023607845230    1.11683767983639   0.909040548584539]
[ -0.435976962986311   0.469221549690931 -0.0198113288181587]
[   20.0000000000000    21.0000000000000    50.0000000000000]
       
Traceback (click to the left of this block for traceback)
...
SyntaxError: can't assign to function call
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_84.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("Qi5yb3cgKDEpID0gR1syXQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpXzosgr/___code___.py", line 3
    B.row (_sage_const_1 ) = G[_sage_const_2 ]
SyntaxError: can't assign to function call
       
[(11.0000000000000, 12.0000000000000, 13.0000000000000),
 (2.35023607845230, 1.11683767983639, 0.909040548584539),
 (-0.435976962986311, 0.469221549690931, -0.0198113288181587),
 (20.0000000000000, 21.0000000000000, 50.0000000000000)]
[(11.0000000000000, 12.0000000000000, 13.0000000000000),
 (2.35023607845230, 1.11683767983639, 0.909040548584539),
 (-0.435976962986311, 0.469221549690931, -0.0198113288181587),
 (20.0000000000000, 21.0000000000000, 50.0000000000000)]
       
<type 'list'>
<type 'list'>
       
(2.35023607845230, 1.11683767983639, 0.909040548584539)
(2.35023607845230, 1.11683767983639, 0.909040548584539)
       
Vector space of dimension 3 over Real Field with 53 bits of precision
Vector space of dimension 3 over Real Field with 53 bits of precision
       
[(11.0000000000000, 2.35023607845230, -0.435976962986311, 20.0000000000000),
 (12.0000000000000, 1.11683767983639, 0.469221549690931, 21.0000000000000),
 (13.0000000000000, 0.909040548584539, -0.0198113288181587, 50.0000000000000)]
[(11.0000000000000, 2.35023607845230, -0.435976962986311, 20.0000000000000),
 (12.0000000000000, 1.11683767983639, 0.469221549690931, 21.0000000000000),
 (13.0000000000000, 0.909040548584539, -0.0198113288181587, 50.0000000000000)]
       
<type 'list'>
<type 'list'>
       
Vector space of dimension 4 over Real Field with 53 bits of precision
Vector space of dimension 4 over Real Field with 53 bits of precision
 
  • blokovi (podmatrice):
       

                                
                            

                                
       

                                
                            

                                
       
[  0.909040548584539   -2.35023607845230   -1.11683767983639]
[-0.0198113288181587   0.435976962986311  -0.469221549690931]
[   50.0000000000000   -20.0000000000000   -21.0000000000000]
[  -13.0000000000000    11.0000000000000    12.0000000000000]
[ -0.909040548584539    2.35023607845230    1.11683767983639]
[  0.909040548584539   -2.35023607845230   -1.11683767983639]
[-0.0198113288181587   0.435976962986311  -0.469221549690931]
[   50.0000000000000   -20.0000000000000   -21.0000000000000]
[  -13.0000000000000    11.0000000000000    12.0000000000000]
[ -0.909040548584539    2.35023607845230    1.11683767983639]
       
Full MatrixSpace of 5 by 3 dense matrices over Real Field with 53 bits of
precision
Full MatrixSpace of 5 by 3 dense matrices over Real Field with 53 bits of precision
       
[-0.0198113288181587]
[   50.0000000000000]
[  -13.0000000000000]
[ -0.909040548584539]
[-0.0198113288181587]
[   50.0000000000000]
[  -13.0000000000000]
[ -0.909040548584539]
       
[20.0000000000000 21.0000000000000]
[20.0000000000000 21.0000000000000]
       
[50.0000000000000]
[50.0000000000000]
       
Full MatrixSpace of 1 by 1 dense matrices over Real Field with 53 bits of
precision
Full MatrixSpace of 1 by 1 dense matrices over Real Field with 53 bits of precision
       
50.0000000000000
50.0000000000000
       
Real Field with 53 bits of precision
Real Field with 53 bits of precision
       
[]
[]
       
[20.0000000000000 21.0000000000000]
[50.0000000000000]
[20.0000000000000 21.0000000000000]
[50.0000000000000]
       
[   11.0000000000000    13.0000000000000   -12.0000000000000]
[   2.35023607845230   0.909040548584539   -1.11683767983639]
[ -0.435976962986311 -0.0198113288181587  -0.469221549690931]
[   20.0000000000000    50.0000000000000   -21.0000000000000]
[  -11.0000000000000   -13.0000000000000    12.0000000000000]
[  -2.35023607845230  -0.909040548584539    1.11683767983639]
[  0.435976962986311  0.0198113288181587   0.469221549690931]
[  -20.0000000000000   -50.0000000000000    21.0000000000000]
[   11.0000000000000    13.0000000000000   -12.0000000000000]
[   2.35023607845230   0.909040548584539   -1.11683767983639]
[ -0.435976962986311 -0.0198113288181587  -0.469221549690931]
[   20.0000000000000    50.0000000000000   -21.0000000000000]
[  -11.0000000000000   -13.0000000000000    12.0000000000000]
[  -2.35023607845230  -0.909040548584539    1.11683767983639]
[  0.435976962986311  0.0198113288181587   0.469221549690931]
[  -20.0000000000000   -50.0000000000000    21.0000000000000]
       
[   11.0000000000000    13.0000000000000   -12.0000000000000]
[   2.35023607845230   0.909040548584539   -1.11683767983639]
[ -0.435976962986311 -0.0198113288181587  -0.469221549690931]
[   20.0000000000000    50.0000000000000   -21.0000000000000]
[  -11.0000000000000   -13.0000000000000    12.0000000000000]
[  -2.35023607845230  -0.909040548584539    1.11683767983639]
[  0.435976962986311  0.0198113288181587   0.469221549690931]
[  -20.0000000000000   -50.0000000000000    21.0000000000000]
[   11.0000000000000    13.0000000000000   -12.0000000000000]
[   2.35023607845230   0.909040548584539   -1.11683767983639]
[ -0.435976962986311 -0.0198113288181587  -0.469221549690931]
[   20.0000000000000    50.0000000000000   -21.0000000000000]
[  -11.0000000000000   -13.0000000000000    12.0000000000000]
[  -2.35023607845230  -0.909040548584539    1.11683767983639]
[  0.435976962986311  0.0198113288181587   0.469221549690931]
[  -20.0000000000000   -50.0000000000000    21.0000000000000]
       
[  2.35023607845230   1.11683767983639  0.909040548584539  -2.35023607845230 
-1.11683767983639 -0.909040548584539]
[  20.0000000000000   21.0000000000000   50.0000000000000  -20.0000000000000 
-21.0000000000000  -50.0000000000000]
[ -11.0000000000000  -12.0000000000000  -13.0000000000000   11.0000000000000  
12.0000000000000   13.0000000000000]
[  2.35023607845230   1.11683767983639  0.909040548584539  -2.35023607845230  -1.11683767983639 -0.909040548584539]
[  20.0000000000000   21.0000000000000   50.0000000000000  -20.0000000000000  -21.0000000000000  -50.0000000000000]
[ -11.0000000000000  -12.0000000000000  -13.0000000000000   11.0000000000000   12.0000000000000   13.0000000000000]
       
[ 2.35023607845230 0.909040548584539]
[ 20.0000000000000  50.0000000000000]
[-11.0000000000000 -13.0000000000000]
[ 2.35023607845230 0.909040548584539]
[ 20.0000000000000  50.0000000000000]
[-11.0000000000000 -13.0000000000000]
       
[   11.0000000000000    13.0000000000000   -13.0000000000000]
[   2.35023607845230   0.909040548584539  -0.909040548584539]
[ -0.435976962986311 -0.0198113288181587  0.0198113288181587]
[   20.0000000000000    50.0000000000000   -50.0000000000000]
[  -11.0000000000000   -13.0000000000000    13.0000000000000]
[  -2.35023607845230  -0.909040548584539   0.909040548584539]
[  0.435976962986311  0.0198113288181587 -0.0198113288181587]
[  -20.0000000000000   -50.0000000000000    50.0000000000000]
[   11.0000000000000    13.0000000000000   -13.0000000000000]
[   2.35023607845230   0.909040548584539  -0.909040548584539]
[ -0.435976962986311 -0.0198113288181587  0.0198113288181587]
[   20.0000000000000    50.0000000000000   -50.0000000000000]
[  -11.0000000000000   -13.0000000000000    13.0000000000000]
[  -2.35023607845230  -0.909040548584539   0.909040548584539]
[  0.435976962986311  0.0198113288181587 -0.0198113288181587]
[  -20.0000000000000   -50.0000000000000    50.0000000000000]
       
[  11.0000000000000   11.0000000000000   11.0000000000000]
[  2.35023607845230   2.35023607845230   2.35023607845230]
[-0.435976962986311 -0.435976962986311 -0.435976962986311]
[  20.0000000000000   20.0000000000000   20.0000000000000]
[ -11.0000000000000  -11.0000000000000  -11.0000000000000]
[ -2.35023607845230  -2.35023607845230  -2.35023607845230]
[ 0.435976962986311  0.435976962986311  0.435976962986311]
[ -20.0000000000000  -20.0000000000000  -20.0000000000000]
[  11.0000000000000   11.0000000000000   11.0000000000000]
[  2.35023607845230   2.35023607845230   2.35023607845230]
[-0.435976962986311 -0.435976962986311 -0.435976962986311]
[  20.0000000000000   20.0000000000000   20.0000000000000]
[ -11.0000000000000  -11.0000000000000  -11.0000000000000]
[ -2.35023607845230  -2.35023607845230  -2.35023607845230]
[ 0.435976962986311  0.435976962986311  0.435976962986311]
[ -20.0000000000000  -20.0000000000000  -20.0000000000000]
       
Traceback (click to the left of this block for traceback)
...
TypeError: 'list' object cannot be interpreted as an index
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_148.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dltbMCwxXV0="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmp4TXY4g/___code___.py", line 3, in <module>
    exec compile(u'v[[_sage_const_0 ,_sage_const_1 ]]
  File "", line 1, in <module>
    
  File "sage/modules/free_module_element.pyx", line 1743, in sage.modules.free_module_element.FreeModuleElement.__getitem__ (build/cythonized/sage/modules/free_module_element.c:12784)
TypeError: 'list' object cannot be interpreted as an index
       
[-0.435976962986311]
[ 0.469221549690931]
[-0.435976962986311]
[ 0.469221549690931]
       
(-0.435976962986311, 0.469221549690931)
(-0.435976962986311, 0.469221549690931)
       
Traceback (click to the left of this block for traceback)
...
IndexError: matrix index out of range
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_151.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("di5yb3coKVtbMCwxXV0="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmp_DvtnI/___code___.py", line 3, in <module>
    exec compile(u'v.row()[[_sage_const_0 ,_sage_const_1 ]]
  File "", line 1, in <module>
    
  File "sage/matrix/matrix0.pyx", line 1006, in sage.matrix.matrix0.Matrix.__getitem__ (build/cythonized/sage/matrix/matrix0.c:7797)
IndexError: matrix index out of range
       
[ -0.435976962986311   0.469221549690931 -0.0198113288181587]
[ -0.435976962986311   0.469221549690931 -0.0198113288181587]

 

Broj redaka i broj stupaca matrice:

       
4
3
4
3
       
1
3
1
3
       
3
1
3
1

 

Neke matrične operacije


Množenje brojem:     \boldsymbol{\mathsf{C}} = d\,\boldsymbol{\mathsf{A}} \quad\Longleftrightarrow\quad c_{i,j} = d\,a_{i,j}

Zbrajanje i oduzimanje:     \boldsymbol{\mathsf{C}} =\boldsymbol{ \mathsf{A}} \pm \boldsymbol{ \mathsf{B}} \quad\Longleftrightarrow\quad c_{i,j} = a_{i,j} \pm b_{i,j}

       
[3.36956541549011 1.75115883630698 1.34692503469065]
[2.95538065572120 1.58834043306303 7.12403283163448]
[1.46954526441944 1.19480106567205 3.09737241476283]
[1.96377762128987 2.06690791501472 1.11490197390420]
[3.36956541549011 1.75115883630698 1.34692503469065]
[2.95538065572120 1.58834043306303 7.12403283163448]
[1.46954526441944 1.19480106567205 3.09737241476283]
[1.96377762128987 2.06690791501472 1.11490197390420]

 

Množenje:    \boldsymbol{\mathsf{C}} = \boldsymbol{\mathsf{A\,B}} \quad\Longleftrightarrow\quad c_{i,j} = \displaystyle\sum_{k = 0}^{n - 1} a_{i,k}\,b_{k,j},  gdje je n broj stupaca prve i broj redaka druge matrice

       
Traceback (click to the left of this block for traceback)
...
TypeError: unsupported operand parent(s) for *: 'Full MatrixSpace of 4 by 3
dense matrices over Real Field with 53 bits of precision' and 'Full MatrixSpace
of 4 by 3 dense matrices over Real Field with 53 bits of precision'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_154.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("RiAqIEc="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpNpxE3H/___code___.py", line 2, in <module>
    exec compile(u'F * G
  File "", line 1, in <module>
    
  File "sage/structure/element.pyx", line 3694, in sage.structure.element.Matrix.__mul__ (build/cythonized/sage/structure/element.c:22617)
TypeError: unsupported operand parent(s) for *: 'Full MatrixSpace of 4 by 3 dense matrices over Real Field with 53 bits of precision' and 'Full MatrixSpace of 4 by 3 dense matrices over Real Field with 53 bits of precision'
       
[0.410637263698667]
[0.410637263698667]
       
0.410637263698667
0.410637263698667
       
[   0.190075912254767   -0.204569786201982  0.00863728297086402]
[  -0.204569786201982    0.220168862694359 -0.00929590240949303]
[ 0.00863728297086402 -0.00929590240949303 0.000392488749541206]
[   0.190075912254767   -0.204569786201982  0.00863728297086402]
[  -0.204569786201982    0.220168862694359 -0.00929590240949303]
[ 0.00863728297086402 -0.00929590240949303 0.000392488749541206]
       
[   0.190075912254767   -0.204569786201982  0.00863728297086402]
[  -0.204569786201982    0.220168862694359 -0.00929590240949303]
[ 0.00863728297086402 -0.00929590240949303 0.000392488749541206]
[   0.190075912254767   -0.204569786201982  0.00863728297086402]
[  -0.204569786201982    0.220168862694359 -0.00929590240949303]
[ 0.00863728297086402 -0.00929590240949303 0.000392488749541206]
       
[-0.302554305288278]
[-0.239882249236039]
[ 0.155541956696427]
[-0.647316675066570]
[-0.302554305288278]
[-0.239882249236039]
[ 0.155541956696427]
[-0.647316675066570]

Vektor se u određenim kontekstima može smatrati jednostupčanom matricom i bez eksplicitne prevorbe, tako da je definirano i množenje matrice i vektora; rezultat je vektor (a ne jednostupčana matrica):

       
(-0.302554305288278, -0.239882249236039, 0.155541956696427, -0.647316675066570)
(-0.302554305288278, -0.239882249236039, 0.155541956696427, -0.647316675066570)

 

Ako je matrica tipa r\times c, njoj transponirana matrica tipa je c\times r. Komponente transponirane matrice  \boldsymbol{\mathsf{B}} = \boldsymbol{\mathsf{A}}^{\mathrm{T}}  su  b_{i,j} = a_{j,i}.

       
[ 0.571160083873278  0.631718302916433 -0.363171469704274  0.734574102913103]
[-0.138788964552110  0.113700337815246 0.0321498498291364 -0.725539613331700]
[-0.584569898932048  0.899398063666802  0.902404893269398 -0.675347588359344]
[ 0.571160083873278  0.631718302916433 -0.363171469704274  0.734574102913103]
[-0.138788964552110  0.113700337815246 0.0321498498291364 -0.725539613331700]
[-0.584569898932048  0.899398063666802  0.902404893269398 -0.675347588359344]
       
[  1.31317021317156   4.42675554775794   6.39342060702989]
[-0.170383083872514  -2.88076392809877  -1.78957239247876]
[  2.11783751735484  -1.61612489373225   1.79101775150042]
[  1.31317021317156   4.42675554775794   6.39342060702989]
[-0.170383083872514  -2.88076392809877  -1.78957239247876]
[  2.11783751735484  -1.61612489373225   1.79101775150042]
       
[  1.31317021317156 -0.170383083872514   2.11783751735484]
[  4.42675554775794  -2.88076392809877  -1.61612489373225]
[  6.39342060702989  -1.78957239247876   1.79101775150042]
[  1.31317021317156 -0.170383083872514   2.11783751735484]
[  4.42675554775794  -2.88076392809877  -1.61612489373225]
[  6.39342060702989  -1.78957239247876   1.79101775150042]
       
[ -0.772331935937980    3.97741335320152    1.84111004622206  
-1.92396429730683]
[  -2.25867572523821    5.49419103476262    3.98581965723256  
-3.24495417307382]
[  0.655958548922348    2.42926127760659 0.00269011214971671  
0.302194238372915]
[  -2.03595286341117    3.02600509976824    2.54073860877768  
-4.50112517440115]
[ -0.772331935937980    3.97741335320152    1.84111004622206   -1.92396429730683]
[  -2.25867572523821    5.49419103476262    3.98581965723256   -3.24495417307382]
[  0.655958548922348    2.42926127760659 0.00269011214971671   0.302194238372915]
[  -2.03595286341117    3.02600509976824    2.54073860877768   -4.50112517440115]
       
[ -0.772331935937980   -2.25867572523821   0.655958548922348  
-2.03595286341117]
[   3.97741335320152    5.49419103476262    2.42926127760659   
3.02600509976824]
[   1.84111004622206    3.98581965723256 0.00269011214971671   
2.54073860877768]
[  -1.92396429730683   -3.24495417307382   0.302194238372915  
-4.50112517440115]
[ -0.772331935937980   -2.25867572523821   0.655958548922348   -2.03595286341117]
[   3.97741335320152    5.49419103476262    2.42926127760659    3.02600509976824]
[   1.84111004622206    3.98581965723256 0.00269011214971671    2.54073860877768]
[  -1.92396429730683   -3.24495417307382   0.302194238372915   -4.50112517440115]

 

Kvadratna je matrica regularna ako joj je determinanta različita od nule; u protivnom je singularna.

Regularne se matrice mogu invertirati.

       
[1 2]
[3 4]
[1 2]
[3 4]
       
-2
-2
       
2
2
       
False
False
       
True
True
       
[  -2    1]
[ 3/2 -1/2]
[  -2    1]
[ 3/2 -1/2]
       

                                
                            

                                
       
[  -2    1]
[ 3/2 -1/2]
[  -2    1]
[ 3/2 -1/2]
       
[  -2    1]
[ 3/2 -1/2]
[  -2    1]
[ 3/2 -1/2]

Prema definiciji, za inverznu matricu vrijedi  \boldsymbol{\mathsf{A}}\,\boldsymbol{\mathsf{A}}^{-1} = \boldsymbol{\mathsf{A}}^{-1}\boldsymbol{\mathsf{A}} = \boldsymbol{\mathsf{I}}.

       
[1 0]
[0 1]
[1 0]
[0 1]
       
True
True
       
True
True

... \boldsymbol{\mathsf{A}} je matrica s racionalnim komponentama, pa je izračunavanje \boldsymbol{\mathsf{A}}^{-1} točno.

       
[1 2]
[3 4]
[1 2]
[3 4]
       
-2
-2
       
2
2
       
False
False
       
False
False

... ops! Da, ali...

       
[  -2    1]
[ 3/2 -1/2]
[  -2    1]
[ 3/2 -1/2]

... naime, rezultat funkcije .is_invertible() je True samo ako komponente inverzne matrice pripaduju skupu kojemu pripadaju komponente izvorne matrice.

       
True
True
       
True
True
       
(a00, a01, a02, a10, a11, a12, a20, a21, a22)
(a00, a01, a02, a10, a11, a12, a20, a21, a22)
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                

 

Sustavi linearnih jednadžbi

 

Manji sustavi linearnih jednadžbi mogu se riješiti funkcijom solve().

Jednadžbe se navode u listi, a sve nepoznanice treba prethodno „uvesti” kao varijable:

       
[[x == 1, y == 1, z == 1]]
[[x == 1, y == 1, z == 1]]

Sustav može imati samo jedno rješenje (kao prethodni) ili bezbroj njih, a može i ne imati rješenje:

  • bezbroj rješenja:
       
[[x == r1 + 2, y == -2*r1 + 4, z == r1]]
[[x == r1 + 2, y == -2*r1 + 4, z == r1]]
       

                                
                            

                                

(novouvedena „slobodna” varijabla r_{N} može poprimiti bilo koju realnu vrijednost); 

  • bez rješenja:
       
[]
[]

 

Veće je sustave pogodnije prikazati u matričnom obliku  \boldsymbol{\mathsf{A}}\cdot \boldsymbol{\mathsf{x}} = \boldsymbol{\mathsf{b}}:

       

                                
                            

                                
       
6
6
       

                                
                            

                                

... funkcija .rref() matricu prevodi u Hermiteov normalni oblik ili reducirani stepeničasti oblik (engl. reduced row echelon form). Prva komponenta u svakom retku dobivene matrice, koja je različita od nule, ima vrijednost 1, a nazivamo je uporišnom komponentom. Stupac s uporišnom komponentom nazivamo baznim stupcem; u njemu sve komponente, osim uporišne, imaju vrijednost 0. Bazni stupci odgovaraju linearno nezavisnim stupcima izvorne matrice.

       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
False
False
       
['5.0000000000000000',
 '-5.0000000000000000',
 '4.0000000000000000',
 '-5.9999999999999973',
 '-4.9999999999999991',
 '-3.0000000000000000']
['5.0000000000000000',
 '-5.0000000000000000',
 '4.0000000000000000',
 '-5.9999999999999973',
 '-4.9999999999999991',
 '-3.0000000000000000']
       

                                
                            

                                
       
6
6
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
(5, -5, 4, -6, -5, -3)
(5, -5, 4, -6, -5, -3)
       
True
True

 

Međutim, sustavi koji imaju — u teoriji — beskonačno mnogo rješenja sada nisu istaknuti. Štoviše, ovisno o greškama zaokruživanja, ponašanje može biti različito:

       

                                
                            

                                
       
6
6
       

                                
                            

                                

... iako je po načinu nastanka očito da je rang 5, što će pokazati i točna racionalna aritmetika.

       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
5
5
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
[1549821734115353/2251799813685248,
 -8214055190811369/4503599627370496,
 -3810738146236571/9007199254740992,
 -2883124255376355/1125899906842624,
 -8988966057869045/4503599627370496,
 0]
[1549821734115353/2251799813685248,
 -8214055190811369/4503599627370496,
 -3810738146236571/9007199254740992,
 -2883124255376355/1125899906842624,
 -8988966057869045/4503599627370496,
 0]
       
[ 0.688259109311741]
[ -1.82388663967611]
[-0.423076923076923]
[ -2.56072874493927]
[ -1.99595141700405]
[ 0.000000000000000]
[ 0.688259109311741]
[ -1.82388663967611]
[-0.423076923076923]
[ -2.56072874493927]
[ -1.99595141700405]
[ 0.000000000000000]
       
[ 0.688259109311741]
[ -1.82388663967611]
[-0.423076923076923]
[ -2.56072874493927]
[ -1.99595141700405]
[ 0.000000000000000]
[ 0.688259109311741]
[ -1.82388663967611]
[-0.423076923076923]
[ -2.56072874493927]
[ -1.99595141700405]
[ 0.000000000000000]
       
['0.68825910931174095',
 '-1.8238866396761131',
 '-0.42307692307692280',
 '-2.5607287449392713',
 '-1.9959514170040482',
 '0.0000000000000000']
['0.68825910931174095',
 '-1.8238866396761131',
 '-0.42307692307692280',
 '-2.5607287449392713',
 '-1.9959514170040482',
 '0.0000000000000000']
       
['0.68825910931174084',
 '-1.8238866396761133',
 '-0.42307692307692307',
 '-2.5607287449392713',
 '-1.9959514170040487',
 '0.0000000000000000']
['0.68825910931174084',
 '-1.8238866396761133',
 '-0.42307692307692307',
 '-2.5607287449392713',
 '-1.9959514170040487',
 '0.0000000000000000']

   

       
       

                                
                            

                                
       

                                
                            

                                
       
[ 0.688259109311741]
[ -1.82388663967611]
[-0.423076923076923]
[ -2.56072874493927]
[ -1.99595141700405]
[-0.000000000000000]
[ 0.688259109311741]
[ -1.82388663967611]
[-0.423076923076923]
[ -2.56072874493927]
[ -1.99595141700405]
[-0.000000000000000]
       
[ 0.688259109311741]
[ -1.82388663967611]
[-0.423076923076923]
[ -2.56072874493927]
[ -1.99595141700405]
[ 0.000000000000000]
[ 0.688259109311741]
[ -1.82388663967611]
[-0.423076923076923]
[ -2.56072874493927]
[ -1.99595141700405]
[ 0.000000000000000]
       
[ 0.688259109311741]
[ -1.82388663967611]
[-0.423076923076923]
[ -2.56072874493927]
[ -1.99595141700405]
[ 0.000000000000000]
[ 0.688259109311741]
[ -1.82388663967611]
[-0.423076923076923]
[ -2.56072874493927]
[ -1.99595141700405]
[ 0.000000000000000]
       
['0.68825910931174095',
 '-1.8238866396761131',
 '-0.42307692307692280',
 '-2.5607287449392713',
 '-1.9959514170040482',
 '-0.0000000000000000']
['0.68825910931174095',
 '-1.8238866396761131',
 '-0.42307692307692280',
 '-2.5607287449392713',
 '-1.9959514170040482',
 '-0.0000000000000000']
       
['0.68825910931174095',
 '-1.8238866396761131',
 '-0.42307692307692280',
 '-2.5607287449392713',
 '-1.9959514170040482',
 '0.0000000000000000']
['0.68825910931174095',
 '-1.8238866396761131',
 '-0.42307692307692280',
 '-2.5607287449392713',
 '-1.9959514170040482',
 '0.0000000000000000']
       
['0.68825910931174084',
 '-1.8238866396761133',
 '-0.42307692307692307',
 '-2.5607287449392713',
 '-1.9959514170040487',
 '0.0000000000000000']
['0.68825910931174084',
 '-1.8238866396761133',
 '-0.42307692307692307',
 '-2.5607287449392713',
 '-1.9959514170040487',
 '0.0000000000000000']
       

                                
                            

                                
       

                                
                            

                                
       
[ 0.688259109311741]
[ -1.82388663967611]
[-0.423076923076923]
[ -2.56072874493927]
[ -1.99595141700405]
[ 0.000000000000000]
[ 0.688259109311741]
[ -1.82388663967611]
[-0.423076923076923]
[ -2.56072874493927]
[ -1.99595141700405]
[ 0.000000000000000]
       
[ 0.688259109311741]
[ -1.82388663967611]
[-0.423076923076923]
[ -2.56072874493927]
[ -1.99595141700405]
[-0.000000000000000]
[ 0.688259109311741]
[ -1.82388663967611]
[-0.423076923076923]
[ -2.56072874493927]
[ -1.99595141700405]
[-0.000000000000000]
       
['0.68825910931174095',
 '-1.8238866396761131',
 '-0.42307692307692280',
 '-2.5607287449392713',
 '-1.9959514170040482',
 '0.0000000000000000']
['0.68825910931174095',
 '-1.8238866396761131',
 '-0.42307692307692280',
 '-2.5607287449392713',
 '-1.9959514170040482',
 '0.0000000000000000']
       
['0.68825910931174084',
 '-1.8238866396761133',
 '-0.42307692307692307',
 '-2.5607287449392713',
 '-1.9959514170040487',
 '0.0000000000000000']
['0.68825910931174084',
 '-1.8238866396761133',
 '-0.42307692307692307',
 '-2.5607287449392713',
 '-1.9959514170040487',
 '0.0000000000000000']
       
['0.68825910931174095',
 '-1.8238866396761131',
 '-0.42307692307692280',
 '-2.5607287449392713',
 '-1.9959514170040482',
 '-0.0000000000000000']
['0.68825910931174095',
 '-1.8238866396761131',
 '-0.42307692307692280',
 '-2.5607287449392713',
 '-1.9959514170040482',
 '-0.0000000000000000']
       

                                
                            

                                
       

                                
                            

                                
       
[4.00000000000000*x0 - 1.00000000000000*x1 - 1.00000000000000*x2 -
1.00000000000000*x5 == 5.00000000000000,
 -1.00000000000000*x0 + 4.00000000000000*x1 - 1.00000000000000*x2 -
1.00000000000000*x3 == -5.00000000000000,
 -1.00000000000000*x0 - 1.00000000000000*x1 + 4.00000000000000*x2 -
1.00000000000000*x3 - 1.00000000000000*x4 == 4.00000000000000,
 -1.00000000000000*x1 - 1.00000000000000*x2 + 4.00000000000000*x3 -
1.00000000000000*x4 - 1.00000000000000*x5 == -6.00000000000000,
 -1.00000000000000*x2 - 1.00000000000000*x3 + 4.00000000000000*x4 -
1.00000000000000*x5 == -5.00000000000000,
 -1.00000000000000*x0 - 1.00000000000000*x3 - 1.00000000000000*x4 +
4.00000000000000*x5 == -3.00000000000000]
[4.00000000000000*x0 - 1.00000000000000*x1 - 1.00000000000000*x2 - 1.00000000000000*x5 == 5.00000000000000,
 -1.00000000000000*x0 + 4.00000000000000*x1 - 1.00000000000000*x2 - 1.00000000000000*x3 == -5.00000000000000,
 -1.00000000000000*x0 - 1.00000000000000*x1 + 4.00000000000000*x2 - 1.00000000000000*x3 - 1.00000000000000*x4 == 4.00000000000000,
 -1.00000000000000*x1 - 1.00000000000000*x2 + 4.00000000000000*x3 - 1.00000000000000*x4 - 1.00000000000000*x5 == -6.00000000000000,
 -1.00000000000000*x2 - 1.00000000000000*x3 + 4.00000000000000*x4 - 1.00000000000000*x5 == -5.00000000000000,
 -1.00000000000000*x0 - 1.00000000000000*x3 - 1.00000000000000*x4 + 4.00000000000000*x5 == -3.00000000000000]
       
[[x0 == (-61/91), x1 == (-269/91), x2 == (-13/7), x3 == (-391/91), x4 ==
(-319/91), x5 == (-261/91)]]
[[x0 == (-61/91), x1 == (-269/91), x2 == (-13/7), x3 == (-391/91), x4 == (-319/91), x5 == (-261/91)]]
       

                                
                            

                                
       

                                
                            

                                
       
[4.00000000000000*x0 - 1.00000000000000*x1 - 1.00000000000000*x2 -
1.00000000000000*x5 == 5.00000000000000,
 -1.00000000000000*x0 + 4.00000000000000*x1 - 1.00000000000000*x2 -
1.00000000000000*x3 == -5.00000000000000,
 -1.00000000000000*x0 - 1.00000000000000*x1 + 4.00000000000000*x2 -
1.00000000000000*x3 - 1.00000000000000*x4 == 4.00000000000000,
 -1.00000000000000*x1 - 1.00000000000000*x2 + 4.00000000000000*x3 -
1.00000000000000*x4 - 1.00000000000000*x5 == -6.00000000000000,
 -1.00000000000000*x2 - 1.00000000000000*x3 + 4.00000000000000*x4 -
1.00000000000000*x5 == -5.00000000000000,
 -4.00000000000000*x0 + 1.00000000000000*x1 + 3.00000000000000*x2 +
2.00000000000000*x3 - 8.00000000000000*x4 + 3.00000000000000*x5 ==
5.00000000000000]
[4.00000000000000*x0 - 1.00000000000000*x1 - 1.00000000000000*x2 - 1.00000000000000*x5 == 5.00000000000000,
 -1.00000000000000*x0 + 4.00000000000000*x1 - 1.00000000000000*x2 - 1.00000000000000*x3 == -5.00000000000000,
 -1.00000000000000*x0 - 1.00000000000000*x1 + 4.00000000000000*x2 - 1.00000000000000*x3 - 1.00000000000000*x4 == 4.00000000000000,
 -1.00000000000000*x1 - 1.00000000000000*x2 + 4.00000000000000*x3 - 1.00000000000000*x4 - 1.00000000000000*x5 == -6.00000000000000,
 -1.00000000000000*x2 - 1.00000000000000*x3 + 4.00000000000000*x4 - 1.00000000000000*x5 == -5.00000000000000,
 -4.00000000000000*x0 + 1.00000000000000*x1 + 3.00000000000000*x2 + 2.00000000000000*x3 - 8.00000000000000*x4 + 3.00000000000000*x5 == 5.00000000000000]
       
[[x0 == 9/19*r2 + 170/247, x1 == 15/38*r2 - 901/494, x2 == 1/2*r2 - 11/26, x3 ==
23/38*r2 - 1265/494, x4 == 10/19*r2 - 493/247, x5 == r2]]
[[x0 == 9/19*r2 + 170/247, x1 == 15/38*r2 - 901/494, x2 == 1/2*r2 - 11/26, x3 == 23/38*r2 - 1265/494, x4 == 10/19*r2 - 493/247, x5 == r2]]
       

                                
                            

                                
       

                                
                            

                                

 

Drugi primjer / druga mogućnost:

       

                                
                            

                                
       
5
5
       

                                
                            

                                
       

                                
                            

                                
       
Traceback (click to the left of this block for traceback)
...
ValueError: matrix equation has no solutions
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_269.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("QTMgXCBiMw=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpLQp4eI/___code___.py", line 2, in <module>
    exec compile(u'A3  * BackslashOperator() * b3
  File "", line 1, in <module>
    
  File "/opt/SageMath/local/lib/python2.7/site-packages/sage/misc/misc.py", line 1173, in __mul__
    return self.left._backslash_(right)
  File "sage/matrix/matrix2.pyx", line 113, in sage.matrix.matrix2.Matrix._backslash_ (build/cythonized/sage/matrix/matrix2.c:5425)
  File "sage/matrix/matrix2.pyx", line 467, in sage.matrix.matrix2.Matrix.solve_right (build/cythonized/sage/matrix/matrix2.c:8036)
  File "sage/matrix/matrix2.pyx", line 583, in sage.matrix.matrix2.Matrix._solve_right_general (build/cythonized/sage/matrix/matrix2.c:9164)
ValueError: matrix equation has no solutions

... dok je:

       

                                
                            

                                
       
5
5
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
(0.688259109311741, -1.82388663967611, -0.423076923076923, -2.56072874493927,
-1.99595141700405, 0.000000000000000)
(0.688259109311741, -1.82388663967611, -0.423076923076923, -2.56072874493927, -1.99595141700405, 0.000000000000000)
       
(0.688259109311741, -1.82388663967611, -0.423076923076923, -2.56072874493927,
-1.99595141700405, 0.000000000000000)
(0.688259109311741, -1.82388663967611, -0.423076923076923, -2.56072874493927, -1.99595141700405, 0.000000000000000)
       
['0.68825910931174095',
 '-1.8238866396761131',
 '-0.42307692307692280',
 '-2.5607287449392713',
 '-1.9959514170040482',
 '0.0000000000000000']
['0.68825910931174095',
 '-1.8238866396761131',
 '-0.42307692307692280',
 '-2.5607287449392713',
 '-1.9959514170040482',
 '0.0000000000000000']
       
['0.68825910931174084',
 '-1.8238866396761133',
 '-0.42307692307692307',
 '-2.5607287449392713',
 '-1.9959514170040487',
 '0.0000000000000000']
['0.68825910931174084',
 '-1.8238866396761133',
 '-0.42307692307692307',
 '-2.5607287449392713',
 '-1.9959514170040487',
 '0.0000000000000000']
       
[4.00000000000000*x0 - 1.00000000000000*x1 - 1.00000000000000*x2 -
1.00000000000000*x5 == 5.00000000000000,
 -1.00000000000000*x0 + 4.00000000000000*x1 - 1.00000000000000*x2 -
1.00000000000000*x3 == -5.00000000000000,
 -1.00000000000000*x0 - 1.00000000000000*x1 + 4.00000000000000*x2 -
1.00000000000000*x3 - 1.00000000000000*x4 == 4.00000000000000,
 -1.00000000000000*x1 - 1.00000000000000*x2 + 4.00000000000000*x3 -
1.00000000000000*x4 - 1.00000000000000*x5 == -6.00000000000000,
 -1.00000000000000*x2 - 1.00000000000000*x3 + 4.00000000000000*x4 -
1.00000000000000*x5 == -5.00000000000000,
 -4.00000000000000*x0 + 1.00000000000000*x1 + 1.00000000000000*x2 +
1.00000000000000*x5 == -5.00000000000000]
[4.00000000000000*x0 - 1.00000000000000*x1 - 1.00000000000000*x2 - 1.00000000000000*x5 == 5.00000000000000,
 -1.00000000000000*x0 + 4.00000000000000*x1 - 1.00000000000000*x2 - 1.00000000000000*x3 == -5.00000000000000,
 -1.00000000000000*x0 - 1.00000000000000*x1 + 4.00000000000000*x2 - 1.00000000000000*x3 - 1.00000000000000*x4 == 4.00000000000000,
 -1.00000000000000*x1 - 1.00000000000000*x2 + 4.00000000000000*x3 - 1.00000000000000*x4 - 1.00000000000000*x5 == -6.00000000000000,
 -1.00000000000000*x2 - 1.00000000000000*x3 + 4.00000000000000*x4 - 1.00000000000000*x5 == -5.00000000000000,
 -4.00000000000000*x0 + 1.00000000000000*x1 + 1.00000000000000*x2 + 1.00000000000000*x5 == -5.00000000000000]
       
       

                                
                            

                                
       

                                
                            

                                

 

I treća mogućnost (drugi sustav na početku odjeljka rješavan funkcijom solve()):

       
[[x == r5 + 2, y == -2*r5 + 4, z == r5]]
[[x == r5 + 2, y == -2*r5 + 4, z == r5]]
       

                                
                            

                                
       
2
2
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
2
2
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
(2.00000000000000, 4.00000000000000, 0.000000000000000)
(2.00000000000000, 4.00000000000000, 0.000000000000000)
       
[2, 4, 0]
[2, 4, 0]

     

Rječnici

 

Rječnik — struktura podataka koja omogućava pristupanje vrijednostima pomoću ključeva.

 

Zadavanje rječnika:

       
{1: 101, 2: 220, 5: 201, 10: 120}
{1: 101, 2: 220, 5: 201, 10: 120}
       
{1: 101, 2: 220, 5: 201, 10: 120}
{1: 101, 2: 220, 5: 201, 10: 120}
       
[(1, 101), (2, 220), (5, 201), (10, 120)]
[(1, 101), (2, 220), (5, 201), (10, 120)]
       
{1: 101, 2: 220, 5: 201, 10: 120}
{1: 101, 2: 220, 5: 201, 10: 120}
       
{1: 101, 2: 220, 5: 201, 10: 120}
{1: 101, 2: 220, 5: 201, 10: 120}
       
True
True
True
True
True
True
True
True
       
True
True
       
{101: 1, 120: 10, 201: 5, 220: 2}
{101: 1, 120: 10, 201: 5, 220: 2}
       
{'four': 7, 'one': 1, 'three': 10, 'two': 2}
{'four': 7, 'one': 1, 'three': 10, 'two': 2}
       
{1: 101/103, 3: 52/53, 5: 107/109, 7: 55/56, 9: 113/115}
{1: 101/103, 3: 52/53, 5: 107/109, 7: 55/56, 9: 113/115}

 

Pristupanje vrijednostima pomoću ključeva:

       
107/109
107/109
       
Traceback (click to the left of this block for traceback)
...
KeyError: 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_142.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZlsyXQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmp8oNVpa/___code___.py", line 3, in <module>
    exec compile(u'f[_sage_const_2 ]
  File "", line 1, in <module>
    
KeyError: 2
       
{1: 101/103, 2: 51/52, 3: 52/53, 5: 107/109, 7: 55/56, 9: 113/115}
{1: 101/103, 2: 51/52, 3: 52/53, 5: 107/109, 7: 55/56, 9: 113/115}
       
{1: 101/103, 2: 103/104, 3: 52/53, 5: 107/109, 7: 55/56, 9: 113/115}
{1: 101/103, 2: 103/104, 3: 52/53, 5: 107/109, 7: 55/56, 9: 113/115}
       
True
True
       
False
False
       
False
False
       
False
False
       
1  =>  101/103
2  =>  103/104
3  =>  52/53
5  =>  107/109
7  =>  55/56
9  =>  113/115
1  =>  101/103
2  =>  103/104
3  =>  52/53
5  =>  107/109
7  =>  55/56
9  =>  113/115
       
2
2
       
four  =>  7
three  =>  10
two  =>  2
one  =>  1
four  =>  7
three  =>  10
two  =>  2
one  =>  1
       
1  =>  101
2  =>  220
10  =>  120
5  =>  201
1  =>  101
2  =>  220
10  =>  120
5  =>  201

 

Ključevi i vrijednosti:

       
{1: 101, 2: 220, 5: 201, 10: 120}
{1: 101, 2: 220, 5: 201, 10: 120}
       
[(1, 101), (2, 220), (10, 120), (5, 201)]
[(1, 101), (2, 220), (10, 120), (5, 201)]
       
[1, 2, 10, 5]
[1, 2, 10, 5]
       
[101, 220, 120, 201]
[101, 220, 120, 201]
       
dict_items([(1, 101), (2, 220), (10, 120), (5, 201)])
dict_items([(1, 101), (2, 220), (10, 120), (5, 201)])
       
dict_keys([1, 2, 10, 5])
dict_keys([1, 2, 10, 5])
       
dict_values([101, 220, 120, 201])
dict_values([101, 220, 120, 201])
       
       
{1: 101, 2: 500, 5: 201, 7: 613, 10: 120}
{1: 101, 2: 500, 5: 201, 7: 613, 10: 120}
       
[(1, 101), (2, 220), (10, 120), (5, 201)]
[(1, 101), (2, 220), (10, 120), (5, 201)]
       
dict_items([(1, 101), (2, 500), (10, 120), (5, 201), (7, 613)])
dict_items([(1, 101), (2, 500), (10, 120), (5, 201), (7, 613)])
       
[1, 2, 10, 5]
[1, 2, 10, 5]
       
dict_keys([1, 2, 10, 5, 7])
dict_keys([1, 2, 10, 5, 7])
       
[101, 220, 120, 201]
[101, 220, 120, 201]
       
dict_values([101, 500, 120, 201, 613])
dict_values([101, 500, 120, 201, 613])

       

       
{1: (4, 1), 2: (5, 2), 3: (6, 3), 4: (4, 5), 5: (5, 6)}
{1: (4, 1), 2: (5, 2), 3: (6, 3), 4: (4, 5), 5: (5, 6)}
       
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5]
       
[(4, 1), (5, 2), (6, 3), (4, 5), (5, 6)]
[(4, 1), (5, 2), (6, 3), (4, 5), (5, 6)]
       
{(4, 1): 1, (4, 5): 4, (5, 2): 2, (5, 6): 5, (6, 3): 3}
{(4, 1): 1, (4, 5): 4, (5, 2): 2, (5, 6): 5, (6, 3): 3}
       
[(6, 3), (5, 2), (5, 6), (4, 1), (4, 5)]
[(6, 3), (5, 2), (5, 6), (4, 1), (4, 5)]
       
[3, 2, 5, 1, 4]
[3, 2, 5, 1, 4]
       
2
2
       
1  =>  (4, 1)
2  =>  (5, 2)
3  =>  (6, 3)
4  =>  (4, 5)
5  =>  (5, 6)
1  =>  (4, 1)
2  =>  (5, 2)
3  =>  (6, 3)
4  =>  (4, 5)
5  =>  (5, 6)
       
1  =>  (4, 1)
2  =>  (5, 2)
3  =>  (6, 3)
4  =>  (4, 5)
5  =>  (5, 6)
1  =>  (4, 1)
2  =>  (5, 2)
3  =>  (6, 3)
4  =>  (4, 5)
5  =>  (5, 6)
       
(1, (4, 1))
(2, (5, 2))
(3, (6, 3))
(4, (4, 5))
(5, (5, 6))
(1, (4, 1))
(2, (5, 2))
(3, (6, 3))
(4, (4, 5))
(5, (5, 6))
       
(6, 3)  =>  3
(5, 2)  =>  2
(5, 6)  =>  5
(4, 1)  =>  1
(4, 5)  =>  4
(6, 3)  =>  3
(5, 2)  =>  2
(5, 6)  =>  5
(4, 1)  =>  1
(4, 5)  =>  4
       
(4, 1)  =>  1
(4, 5)  =>  4
(5, 2)  =>  2
(5, 6)  =>  5
(6, 3)  =>  3
(4, 1)  =>  1
(4, 5)  =>  4
(5, 2)  =>  2
(5, 6)  =>  5
(6, 3)  =>  3

 

Skup — struktura podataka koja sadrži jedinstvene komponente

 

       
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 3, 5, 7, 9]
[0, 1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 9]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 3, 5, 7, 9]
[0, 1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 9]
       
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

  

       
{1: 101, 2: 500, 5: 201, 7: 613, 10: 120}
{101: 1, 120: 10, 201: 5, 220: 2}
{1: 101, 2: 500, 5: 201, 7: 613, 10: 120}
{101: 1, 120: 10, 201: 5, 220: 2}
       
dict_keys([1, 2, 10, 5, 7])
dict_keys([120, 201, 220, 101])
dict_keys([1, 2, 10, 5, 7])
dict_keys([120, 201, 220, 101])
       
{1, 2, 5, 7, 10, 101, 120, 201, 220}
{1, 2, 5, 7, 10, 101, 120, 201, 220}
       
{1, 2, 5, 7, 10}
{1, 2, 5, 7, 10}
       
{1, 2, 5, 7, 10}
{1, 2, 5, 7, 10}

 

Binarno stablo

  

       
       
       
107/109
107/109
       
[10, 11, 15, 19, 21, 30, 70, 81, 110]
[10, 11, 15, 19, 21, 30, 70, 81, 110]
       
[10, 11, 15, 19, 21, 30, 70, 81, 110]
[10, 11, 15, 19, 21, 30, 70, 81, 110]
       
[30, 19, 11, 10, 15, 21, 110, 70, 81]
[30, 19, 11, 10, 15, 21, 110, 70, 81]
       
[10, 15, 11, 21, 19, 81, 70, 110, 30]
[10, 15, 11, 21, 19, 81, 70, 110, 30]
       
[110/113, 101/103, 107/109, 113/115, 103/104, 52/53, 55/56, 107/113, 111/113]
[110/113, 101/103, 107/109, 113/115, 103/104, 52/53, 55/56, 107/113, 111/113]
       
[110/113, 101/103, 107/109, 113/115, 103/104, 52/53, 55/56, 107/113, 111/113]
[110/113, 101/103, 107/109, 113/115, 103/104, 52/53, 55/56, 107/113, 111/113]
       
       
[10, 11, 15, 19, 21, 30, 70, 81, 110]
[10, 11, 15, 19, 21, 30, 70, 81, 110]
       
[70, 30, 19, 11, 10, 15, 21, 110, 81]
[70, 30, 19, 11, 10, 15, 21, 110, 81]
       
[10, 15, 11, 21, 19, 30, 81, 110, 70]
[10, 15, 11, 21, 19, 30, 81, 110, 70]