1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 9 16:03:05 2015
@author: camilstaps
"""
from __future__ import print_function
import numpy as np
# 1.1.1
vector_x = np.array([6,7,8,9,10,11,12])
vector_y = np.array([3,7,11,15,19,23,27])
vector_w = np.array([1,1,0,0.5,1,1.5,2,0,0])
vector_s = np.array([100,98.8,97.6,96.4,95.2])
vector_z = np.array([0.7 + 0.3 * i for i in range(0,7)])
# 1.1.1 a
vector_v = np.multiply(3, vector_x) + vector_y
print("1.1.1 a:", vector_v)
# 1.1.1 b
dot_product = np.dot(vector_x, vector_y)
print("1.1.1 b:", dot_product)
# 1.1.1 c
vector_t = np.multiply(np.pi, vector_s + 4)
print("1.1.1 c:", vector_t)
# 1.1.1 d
vector_z = vector_z - 1
print("1.1.1 d:", vector_z)
# 1.1.1 e
vector_x = np.concatenate((vector_x[:4], [4,4,4]))
print("1.1.1 e:", vector_x)
# 1.1.1 f
vector_r = np.multiply(2, vector_w) - 5
print("1.1.1 f:", vector_r)
# 1.1.2
matrix_m = np.asmatrix([[1,2,3],[6,8,4],[6,7,5]])
matrix_n = np.asmatrix([[4,6],[7,2],[5,1]])
matrix_p = np.asmatrix([[2,5],[5,5]])
# 1.1.2 a
matrix_a = matrix_m * matrix_n + matrix_n
print("1.1.2 a:", matrix_a)
# 1.1.2 b
matrix_b = np.dot(np.transpose(matrix_n), matrix_m)
print("1.1.2 b:", matrix_b)
# 1.1.2 c
matrix_c = np.invert(matrix_p) + matrix_p
print("1.1.2 c:", matrix_c)
# 1.1.2 d
#matrix_d = matrix_a * matrix_c * (matrix_c + matrix_b)
print("1.1.2 d: C and B cannot be added")
# 1.1.2 e
# Only square matrices have eigenvalues (see for example
# http://math.stackexchange.com/q/583938/63495), so N is omitted
val_m, vec_m = np.linalg.eig(matrix_m)
val_p, vec_p = np.linalg.eig(matrix_p)
print("1.1.2 e (M):", val_m, vec_m)
print("1.1.2 e (N): non-square matrices don't have eigenv*s")
print("1.1.2 e (P):", val_p, vec_p)
|