import numpy as np

"""
Explanation: Matrix Computations
End of explanation
"""


x = np.array([1,5,2])
y = np.array([7,4,1])

x + y

x * y

x - y

x / y

x % y

"""
Explanation: Basic matrix arithmetics like
Matrix addition
Matrix subtraction
Matrix multiplication
Scalar product
Cross product
and other operations on matrices

The arithemtic standard Operators
+
-
*
/
**
%

are applied on the elements, this means that the arrays have to have the same size.
End of explanation
"""


x = np.array([1,2,3])
y = np.array([-7,8,9])
dot = np.dot(x,y)
np.dot(x,y)

"""
Explanation: In mathematics, the dot product is an algebraic operation that takes two coordinate vectors of equal size and returns a single number. The result is calculated by multiplying corresponding entries and adding up those products. The name "dot product" stems from the fact that the centered dot "·" is often used to designate this operation.
End of explanation
"""


x = np.array( ((2,3), (3, 5)) )
y = np.array( ((1,2), (5, -1)) )

x * y

x = np.matrix( ((2,3), (3, 5)) )
y = np.matrix( ((1,2), (5, -1)) )

x * y

"""
Explanation: Matrices
The matrix objects are a subclass of the numpy arrays (ndarray). The matrix objects inherit all the attributes and methods of ndarry. Another difference is that numpy matrices are strictly 2-dimensional, while numpy arrays can be of any dimension, i.e. they are n-dimensional.
The most important advantage of matrices is that the provide convenient notations for the matrix mulitplication. If X and Y are two Matrices than X * Y defines the matrix multiplication. While on the other hand, if X and Y are ndarrays, X * Y define an element by element multiplication.
End of explanation
"""


x = np.array( ((2,3), (3, 5)) )
y = np.array( ((1,2), (5, -1)) )
np.dot(x,y)

"""
Explanation: If we want to perform matrix multiplication with two numpy arrays (ndarray), we have to use the dot product:
End of explanation
"""


np.mat(x) * np.mat(y)

"""
Explanation: Alternatively, we can cast them into matrix objects and use the "*" operator:
End of explanation
"""


NumPersons = np.array([[100,175,210],[90,160,150],[200,50,100],[120,0,310]])
Price_per_100_g = np.array([2.98,3.90,1.99])
Price_in_Cent = np.dot(NumPersons,Price_per_100_g)
Price_in_CAD = Price_in_Cent / np.array([100,100,100,100])
Price_in_CAD

"""
Explanation: In the following practical example, we come to talk about the sweet things of life.
Let's assume there are four people, and we call them Lucas, Mia, Leon and Hannah. Each of them has bought chocolates out of a choice of three. The brand are A, B and C, not very marketable, we have to admit. Lucas bought 100 g of brand A, 175 g of brand B and 210 of C. Mia choose 90 g of A, 160 g of B and 150 g of C. Leon bought 200 g of A, 50 of B and 100 g of C. Hannah apparently didn't like brand B, because she hadn't bought any of those. But she she seems to be a real fan of brand C, because she bought 310 g of them. Furthermore she bought 120 g of A.
So, what's the price in Euro of these chocolates: A costs 2.98 per 100 g, B costs 3.90 and C only 1.99 CAD.
If we have to calculate how much each of them had to pay, we can use Python, NumPy and Matrix multiplication:
End of explanation
"""


H = np.matrix( ((3,-1,0), (-1,3,0), (0,0,5)) )
eigenvalues, eigenvectors = np.linalg.eig(H)

eigenvalues

determinant = np.linalg.det(H)

determinant

"""
Explanation: This means that Lucas paid 13.98 CAD, Mia 11.97 CAD, Leon 9.90 and Hannah 9.75.
Computing determinants and eigenvalues
End of explanation
"""


