Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to learn Julia Matrix Operation

Shulou Source: shulou.com Published: 2022-06-01 15:07:54 11月12日 Update

This article is about how to learn Julia matrix operation, the editor feels very practical, so share with you to learn, I hope you can get something after reading this article, say no more, follow the editor to have a look.

1.1 Generation of Matrix

Generate a matrix of 4 rows and 4 columns, using 1-16 numbers. Note that when you generate a matrix here, you need to define an empty array first, and then fill it.

Mat = Array (Int32,4,4)

4 × 4 Array {Int32,2}:

125804192 256236432 79364176 79364176

0 0 0

79234864 79266064 125805712 248775184

0 0 0

Mat [:] = 1:16

Mat

4 × 4 Array {Int32,2}:

1 5 9 13

2 6 10 14

3 7 11 15

4 8 12 16

You can also use reshape to build a matrix reshape (1)

3 × 5 Base.ReshapedArray {Int64,2,UnitRange {Int64}, Tuple {}}:

1 4 7 10 13

2 5 8 11 14

3 6 9 12 15

1.2 extract main diagonal diag (mat)

4-element Array {Int64,1}:

one

six

eleven

sixteen

1.3 generate a diagonal matrix eye (4) with a diagonal of 1

4 × 4 Array {Float64,2}:

1.0 0.0 0.0 0.0

0.0 1.0 0.0 0.0

0.0 0.0 1.0 0.0

0.0 0.0 0.0 1.0

1.4 extract the lower triangular tril (mat) of the matrix

4 × 4 Array {Int64,2}:

1 0 0 0

2 6 0 0

3 7 11 0

4 8 12 16

1.5 extract the upper triangle triu (mat) of the matrix

4 × 4 Array {Int64,2}:

1 5 9 13

0 6 10 14

0 0 11 15

0 0 0 16

1.6 Matrix transpose mat'

4 × 4 Array {Int64,2}:

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

1.7 Matrix multiplication a = [[1] [1] [2]

2 × 2 Array {Int64,2}:

1 2

3 4

B = [[2pr 4] [3pm 5]]

2 × 2 Array {Int64,2}:

2 3

4 5

Multiply the corresponding values

A. Roomb

2 × 2 Array {Int64,2}:

2 6

12 20

Matrix multiplication

Axib

2 × 2 Array {Int64,2}:

10 13

22 29

1.8 Matrix inverse inv (a)

2 × 2 Array {Float64,2}:

-2.0 1.0

1.5-0.5

Inv (a) * a

2 × 2 Array {Float64,2}:

1.0 0.0

2.22045e-16 1.0

The above is how to learn Julia matrix operation, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Matrix generation learning diagonal diagonal more knowledge article triangle practical that is work meeting numerical value number array article look knowledge point industry details Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Microsoft Shulou Information Docker Xiaomi