Warning: This is no longer the latest available version of this module. Please see the releases page for the most recent version. The Webnucleo group strongly recommends the use of the latest version of any of its online modules.
This tutorial demonstrates how to use the example codes in the wn_matrix distribution src/examples directory. The sample input and output files used in the tutorial are included in the distribution release and may be located in the data_pub directory.
Example 1: Create a matrix, store elements, and scale them.
wn_matrix routines demonstrated in example1.c are:
- WnMatrix__new()
- WnMatrix__assignElement()
- WnMatrix__removeElement()
- WnMatrix__getElement()
- WnMatrix__getNumberOfElements()
- WnMatrix__scaleMatrix()
- WnMatrix__clear()
- WnMatrix__free()
To run example1, type the following on the command line:
example1
The result of running example1 is the following:
Example 2: Print out a matrix to a file.
wn_matrix routines demonstrated in example2.c are:
To run example2 with a cutoff parameter of 2.0, type the following on the command line:
example2 ex2_output.txt 2.0
The output will be stored in the file ex2_output.txt. If the file does not already exist, it will be created. If it does exist, the contents will be over-written.
Example 3: Convert a matrix to compressed row format.
wn_matrix routines demonstrated in example3.c are:
- WnMatrix__new()
- WnMatrix__assignElement()
- WnMatrix__getCsrMatrix()
- WnMatrix__getElement()
- WnMatrix__free()
To run example3, type the following on the command line:
example3 ex3_output.txt
The output will be stored in the file ex3_output.txt.
Example 4: Convert a matrix to Yale sparse format.
wn_matrix routines demonstrated in example4.c are:
- WnMatrix__new()
- WnMatrix__assignElement()
- WnMatrix__getNumberOfElements()
- WnMatrix__getNumberOfRows()
- WnMatrix__getYaleSparseMatrix()
- WnMatrix__getElement()
- WnMatrix__free()
To run example4, type the following on the command line:
example4 ex4_output.txt
ex4_output.txt is the output file.
Example 5: Multipy a matrix by a vector and a transpose matrix by a vector.
wn_matrix routines demonstrated in example5.c are:
- WnMatrix__new()
- WnMatrix__assignElement()
- WnMatrix__getMatrixTimesVector()
- WnMatrix__getElement()
- WnMatrix__getTransposeMatrixTimesVector()
- WnMatrix__free()
To run example5, type the following on the command line:
example5
The result of running example5 is the following:
Example 6: Insert a smaller matrix into a larger one and extract a smaller matrix from a larger one.
wn_matrix routines demonstrated in example6.c are:
- WnMatrix__new()
- WnMatrix__assignElement()
- WnMatrix__insertMatrix()
- WnMatrix__getDenseMatrix()
- WnMatrix__getElement()
- WnMatrix__free()
- WnMatrix__extractMatrix()
- WnMatrix__getNumberOfRows()
- WnMatrix__getNumberOfColumns()
To run example6, type the following on the command line:
example6 ex6_output.txt
ex6_output.txt is the output file.
Example 7: Print out the non-zero elements of a row or column of a matrix.
wn_matrix routines demonstrated in example7.c are:
- WnMatrix__new()
- WnMatrix__assignElement()
- WnMatrix__getRow()
- WnMatrix__getColumn()
- WnMatrix__Line__getNonZeroIndices()
- WnMatrix__Line__getNonZeroElements()
- WnMatrix__Line__getNumberOfElements()
- WnMatrix__Line__free()
- WnMatrix__free()
To run example7, type the following on the command line:
example7 ../../data_pub/ex7_input.txt row 1
ex7_input.txt is the input file.
The result of running example7 is the following:
Try other rows and columns. For example, try
example7 ../../data_pub/ex7_input.txt column 2
Example 8: Get the transfer matrix form of a matrix.
wn_matrix routines demonstrated in example8.c are:
- WnMatrix__new()
- WnMatrix__assignElement()
- WnMatrix__getTransferMatrix()
- WnMatrix__getNumberOfRows()
- WnMatrix__getNumberOfColumns()
- WnMatrix__getElement()
- WnMatrix__free()
To run example8, type the following on the command line:
example8 ../../data_pub/ex8_input.txt ex8_output.txt
ex8_input.txt is the input file. ex8_output.txt is the output file.
Example 9: Get a copy of a matrix and the transpose of a matrix.
wn_matrix routines demonstrated in example9.c are:
- WnMatrix__new()
- WnMatrix__assignElement()
- WnMatrix__getCopy()
- WnMatrix__getTranspose()
- WnMatrix__getNumberOfRows()
- WnMatrix__getNumberOfColumns()
- WnMatrix__getElement()
- WnMatrix__free()
To run example9, type the following on the command line:
example9 ../../data_pub/ex9_input.txt ex9_output.txt
ex9_input.txt is the input file. ex9_output.txt is the output file.