Algebra | SageMath computing

This article introduces the application of SageMath in Algebra.

Open a Jupyter notebook is easy, just type jupyter notebook in the terminal.

Vectors and Matries

Basic operations

Initialization

1
2
3
4
5
6
7
8
9
10
11
12
13
X = vector(
[0.0769727234, 0.084649211, 0.090481564, 0.084548456]
)
A = matrix(
[[0.2, 0.5, 0.1, -0.3],
[-0.5, 0.5, 0.5, -0.3],
[0.2, -0.3, 0.5, 0.4],
[-0.3, -0.3, 0.5, 0]]
)
# Specify element type
B = matrix(ZZ, 3,3) # integer
C = matrix(QQ, 3,3) # fraction
D = matrix(RR, 3,3) # common real numbers

Matrix manipulations

1
2
# transpose matrix A
A = A.transpose()

Working with MATLAB

Data sharing

Load .mat data file from Sage

Here I leverage Scipy function to load NN.mat file generated by a MATLAB program:

1
2
3
4
import scipy.io
data = scipy.io.loadmat('NN.mat')
x = data['NN']
print(x)
VSCode for LeetCode TBAC project development

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×