forked from Visualize-ML/Book3_Elements-of-Mathematics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBk3_Ch23_1.py
More file actions
36 lines (24 loc) · 676 Bytes
/
Bk3_Ch23_1.py
File metadata and controls
36 lines (24 loc) · 676 Bytes
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
###############
# Authored by Weisheng Jiang
# Book 3 | From Basic Arithmetic to Machine Learning
# Published and copyrighted by Tsinghua University Press
# Beijing, China, 2022
###############
# Bk3_Ch24_1
import numpy as np
A = np.array([[1,1],
[2,4]])
b = np.array([[35],
[94]])
A_inv = np.linalg.inv(A)
x = A_inv@b
print(x)
x_ = np.linalg.solve(A,b)
print(x_)
from sympy import *
x1, x2 = symbols(['x1', 'x2'])
sol = solve([x1 + x2 - 35, 2*x1 + 4*x2 - 94], [x1, x2])
print(sol)
from sympy.solvers.solveset import linsolve
sol_ = linsolve([x1 + x2 - 35, 2*x1 + 4*x2 - 94], [x1, x2])
print(sol_)