Used built-in functions for construction of matrices
Reduced arguments to write_output_file by extracting calculations and element number calcs