This tutorial demonstrates how to use example codes in the wn_matrix distribution examples/ directory.

Example 1: Create a matrix, store elements, and scale them.

The example code is create_matrix.c

To run create_matrix, type the following on the command line:


./create_matrix > ex1_output.txt

The result is ex1_output.txt

Example 2: Print out a matrix to a file.

The example code is print_matrix_to_file.c

To run print_matrix_to_file, type the following on the command line:


./print_matrix_to_file 2.0 ex2_output.txt

The result is ex2_output.txt

Example 3: Convert a matrix to compressed row format.

The example code is convert_to_csr.c

To run convert_to_csr, type the following on the command line:


./convert_to_csr ex3_output.txt

The result is ex3_output.txt

Example 4: Convert a matrix to Yale sparse format.

The example code is convert_to_yale.c

To run convert_to_yale, type the following on the command line:


./convert_to_yale ex4_output.txt

The result is ex4_output.txt

Example 5: Insert a smaller matrix into a larger one and extract a smaller matrix from a larger one.

The example code is insert_and_extract.c

To run insert_and_extract, type the following on the command line:


./insert_and_extract ex5_output.txt

The result is ex5_output.txt

Example 6: Convert ascii coordinate matrix data into XML data and write to a file.

The example code is ascii_matrix_to_xml.c

To run ascii_matrix_to_xml, type the following on the command line:


./ascii_matrix_to_xml ../data_pub/matrix.txt ex6_output.xml

The result is ex6_output.xml

Output the matrix element values in format other than default.


./ascii_matrix_to_xml ../data_pub/matrix.txt ex6_output_with_formatting.xml %.12e

The result is ex6_output_with_formatting.xml

Example 7: Print out the data from a matrix in XML format.

The example code is print_xml_matrix.c

To run print_xml_matrix, type the following on the command line:


./print_xml_matrix ../data_pub/matrix.xml > ex7_output.txt

The result is ex7_output.txt

Use an XPath expression to select out particular rows, columns, or values:


./print_xml_matrix ../data_pub/matrix.xml "[row < 3 or value > 0]" > ex7_output_xpath.txt

The result is ex7_output_xpath.txt

Example 8: Print out the non-zero elements of a row or column of a matrix.

The example code is print_row_or_column.c

To run print_row_or_column, type the following on the command line:


./print_row_or_column ../data_pub/matrix.xml row 1 > ex8_output.txt

The result is ex8_output.txt

Try other rows or columns. For example, try


./print_row_or_column ../data_pub/matrix.xml column 2 > ex8_output_column.txt

The result is ex8_output_column.txt

Example 9: Insert and remove rows and columns.

The example code is insert_and_delete.c

To run insert_and_delete, type the following on the command line:


./insert_and_delete ../data_pub/matrix.xml > ex9_output.txt

The result is ex9_output.txt

Example 10: Get the transfer matrix form of a matrix.

The example code is get_transfer.c

To run get_transfer, type the following on the command line:


./get_transfer ../data_pub/matrix.xml ex10_output.txt

The result is ex10_output.txt

Example 11: Get a copy of a matrix and the transpose of a matrix.

The example code is get_copy_and_transpose.c

To run get_copy_and_transpose, type the following on the command line:


./get_copy_and_transpose ../data_pub/matrix.xml ex11_output.txt

The result is ex11_output.txt

Example 12: Convert ascii vector data into XML data and write to a file.

The example code is vector_to_xml.c

To run vector_to_xml, type the following on the command line:


./vector_to_xml ../data_pub/vector.txt ex12_output.xml

The result is ex12_output.xml

To output the vector data in a format other than the default, enter the format code as well:


./vector_to_xml ../data_pub/vector.txt ex12_output_with_formatting.xml %.14e

The result is ex12_output_with_formatting.xml

Example 13: Print out the data from a vector in XML format.

The example code is print_xml_vector.c

To run print_xml_vector, type the following on the command line:


./print_xml_vector ../data_pub/vector.xml > ex13_output.txt

The result is ex13_output.txt

Use an XPath expression to select out particular elements (here only the elements larger than zero):


./print_xml_vector ../data_pub/vector.xml "[. > 0]" > ex13_output_xpath.txt

The result is ex13_output_xpath.txt

Example 14: Read in coordinate matrix data from an XML file, convert to compressed sparse row format, and output to an XML file.

The example code is convert_coo_to_csr.c

To run convert_coo_to_csr, type the following on the command line:


./convert_coo_to_csr ../data_pub/matrix.xml ex14_csr.xml

The result is ex14_csr.xml

To output the matrix element values with a format other than the default, input the desired format code:


./convert_coo_to_csr ../data_pub/matrix.xml ex14_csr_with_formatting.xml %.12e

The result is ex14_csr_with_formatting.xml

Example 15: Read in coordinate matrix data from an XML file, convert to Yale sparse format, and output to an XML file.

The example code is convert_coo_to_yale.c

To run convert_coo_to_yale, type the following on the command line:


./convert_coo_to_yale ../data_pub/matrix.xml ex15_yale.xml

The result is ex15_yale.xml

To output the matrix element values with a format other than the default, input the desired format code:


./convert_coo_to_yale ../data_pub/matrix.xml ex15_yale_with_formatting.xml %.10f

The result is ex15_yale_with_formatting.xml

Example 16: Multiply a matrix by a vector and a transpose matrix by a vector.

The example code is matrix_times_vector.c

To run matrix_times_vector, type the following on the command line:


./matrix_times_vector ../data_pub/matrix.xml ../data_pub/vector.xml > ex16_output.txt

The result is ex16_output.txt

Example 17: Multiply a matrix by another matrix.

The example code is matrix_times_matrix.c

To run matrix_times_matrix, type the following on the command line:


./matrix_times_matrix ../data_pub/matrix.xml ../data_pub/matrix.xml > ex17_output.txt

The result is ex17_output.txt

Example 18: Solve a matrix equation.

The example code is solve_matrix_equation.c

To run solve_matrix_equation, type the following on the command line:


./solve_matrix_equation ../data_pub/matrix.xml ../data_pub/vector.xml > ex18_output.txt

The result is ex18_output.txt

Example 19: Convert to arrow matrix form.

The example code is get_arrow_matrix.c

To run get_arrow_matrix, type the following on the command line:


./get_arrow_matrix ../data_pub/matrix2.xml 3 > ex19_output.txt

The result is ex19_output.txt

Example 20: Solve a matrix equation with the arrow solver.

The example code is solve_by_arrow.c

To run solve_by_arrow, type the following on the command line:


./solve_by_arrow ../data_pub/matrix2.xml ../data_pub/vector2.xml > ex20_output.txt

The result is ex20_output.txt