2021/10/15 MatLab上課筆記
MatLab作業
Date:2021/10/15
Thought
Matlab brings great convenience for developiong a project.
I remember that when I was in sophomore, I toughly finish the HW of data structure with C++ at that time. HW is about a sparse matrix. I wrote a sparse matrix for a long time.
When I use matlab. I can finish sparse matrix with several lines.
(245 char)
Note
1.Common useful instruction
Look for:look for related instruction
Ver:show current version
What:show files which is in the directory
Which:find its path of current file
Path: show current path
Help:show info about this insturction
2.Conversion:
2 represent to
num2str:Float num to string
int2str:integer to string
cart2pol:cart to polarization
dec2base(char array num,int baseNum): convert integer num to baseNum base from decimal
base2dec(char array num,int baseNum):convert integer num which is the base of baseNum to decimal number from the base baseNum
Screenshot:
Example for base conversion
Char type
String type
Integer type
inte
3.Matrix:
How to create a matrix?
bracket []
4.Matrix operator:
Note that ‘.’ means operation of vector
+
add(number ot vector)
-
minus(number or vector)
*
multiplication(number)
/
right division (number)
\
left division(number)
^
power(number)
.*
multiplication(vector)
./
right division (vector)
.^
power(number)
5.Data Table:
How to create a table?
table() func.
If one would like to create an empty table, call “table” without arguments.
e.g. t1=table
For more details on:
6.Sparse matrix:
Sp is abbreviation of sparse
How to create a sparse matrix?
sparse() func.
[syntax]
S=sparse(matrix A)
S=sparse(int m,int n)
Create a m*n sparse matrix with all value zero
S=spare(int i,int j,int v)
generates a sparse matrix S from the triplets i, j, and v such that S(i(k),j(k))
S=spare(int i,int j,int v,int m,int n)
specifies the S which size is m*n.
S=spare(int i,int j,int v,int m,int n,int nz)
allocates space for nz nonzero elements. Use this syntax to allocate extra space for nonzero values to be filled in after construction
For more details on:
Methods for generation of special matrix
speye(int a)
a*a sparse identity matrix
speye(int a,int b)
a*b sparse identity matrix
sprandn(int a,int b,int c)
Radnomly generate a sparse matrix which size is a*b with c density of nonzero value , where c is between 0 (exclusive) and 1 (exclusive)
i.e. there are probability c approximately that value of one of all element in the spare matrix will be equal to nonzeros
Methods:
issparse(sp)
Check sp is a sparse matrix, return true iff sp is a sparse matrix
nonzeros(sp)
Find all element in sparse matrix sp which its value is not equal to zero
nnz(sp)
Count number of elements in sparse matrix sp which its value is not equal to zero
.
7.Cell matrix
How to create a cell matrix?
First way:
Cell() func.
Second way:
Bracket {} if one would like to create an empty cell matrix
More details on:
Comments
Post a Comment