# include # include # include "ppc_array.h" /******************************************************************************/ void free_matrix_double ( double **a ) /******************************************************************************/ /* Purpose: free_matrix_double() releases memory and pointers for a 2D double matrix. Licensing: This code is distributed under the MIT license. Modified: 28 July 2019 Author: John Burkardt Reference: Rouben Rostamian, Programming Projects in C for Students of Engineering, Science, and Mathematics, SIAM, 2014, ISBN: 978-1-611973-49-5 Input: double **a, pointers to the initial elements of each row. */ { if ( a != NULL ) { for ( size_t i = 0; a[i] != NULL; i++ ) { free_vector ( a[i] ); } free ( a ); } return; } /******************************************************************************/ void free_matrix_float ( float **a ) /******************************************************************************/ /* Purpose: free_matrix_float() releases memory and pointers for a 2D float matrix. Licensing: This code is distributed under the MIT license. Modified: 28 July 2019 Author: John Burkardt Reference: Rouben Rostamian, Programming Projects in C for Students of Engineering, Science, and Mathematics, SIAM, 2014, ISBN: 978-1-611973-49-5 Input: float **a, pointers to the initial elements of each row. */ { if ( a != NULL ) { for ( size_t i = 0; a[i] != NULL; i++ ) { free_vector ( a[i] ); } free ( a ); } return; } /******************************************************************************/ void free_matrix_int ( int **a ) /******************************************************************************/ /* Purpose: free_matrix_int() releases memory and pointers for a 2D int matrix. Licensing: This code is distributed under the MIT license. Modified: 05 September 2023 Author: John Burkardt Reference: Rouben Rostamian, Programming Projects in C for Students of Engineering, Science, and Mathematics, SIAM, 2014, ISBN: 978-1-611973-49-5 Input: int **a, pointers to the initial elements of each row. */ { if ( a != NULL ) { for ( size_t i = 0; a[i] != NULL; i++ ) { free_vector ( a[i] ); } free ( a ); } return; } /******************************************************************************/ void free_vector_int ( int *a ) /******************************************************************************/ /* Purpose: free_vector_int() releases memory and pointers for an int vector. Licensing: This code is distributed under the MIT license. Modified: 05 September 2023 Author: John Burkardt Reference: Rouben Rostamian, Programming Projects in C for Students of Engineering, Science, and Mathematics, SIAM, 2014, ISBN: 978-1-611973-49-5 Input: int *a, pointers to the elements of the vector. */ { if ( a != NULL ) { free ( a ); } return; } /******************************************************************************/ double **make_matrix_double ( size_t m, size_t n ) /******************************************************************************/ /* Purpose: make_matrix_double() sets up memory and pointers for a 2D double matrix. Licensing: This code is distributed under the MIT license. Modified: 28 July 2019 Author: John Burkardt Reference: Rouben Rostamian, Programming Projects in C for Students of Engineering, Science, and Mathematics, SIAM, 2014, ISBN: 978-1-611973-49-5 Input: size_t m, n, the number of rows and columns. Output: double **make_matrix_double, pointers to the initial elements of each row. */ { double **a; make_vector ( a, m + 1 ); for ( size_t i = 0; i < m; i++ ) { make_vector ( a[i], n ); } a[m] = NULL; return a; } /******************************************************************************/ float **make_matrix_float ( size_t m, size_t n ) /******************************************************************************/ /* Purpose: make_matrix_float() sets up memory and pointers for a 2D float matrix. Licensing: This code is distributed under the MIT license. Modified: 28 July 2019 Author: John Burkardt Reference: Rouben Rostamian, Programming Projects in C for Students of Engineering, Science, and Mathematics, SIAM, 2014, ISBN: 978-1-611973-49-5 Input: size_t m, n, the number of rows and columns. Output: float **make_matrix_float, pointers to the initial elements of each row. */ { float **a; make_vector ( a, m + 1 ); for ( size_t i = 0; i < m; i++ ) { make_vector ( a[i], n ); } a[m] = NULL; return a; } /******************************************************************************/ int **make_matrix_int ( size_t m, size_t n ) /******************************************************************************/ /* Purpose: make_matrix_int() sets up memory and pointers for a 2D int matrix. Licensing: This code is distributed under the MIT license. Modified: 05 September 2023 Author: John Burkardt Reference: Rouben Rostamian, Programming Projects in C for Students of Engineering, Science, and Mathematics, SIAM, 2014, ISBN: 978-1-611973-49-5 Input: size_t m, n, the number of rows and columns. Output: int **make_matrix_int, pointers to the initial elements of each row. */ { int **a; make_vector ( a, m + 1 ); for ( size_t i = 0; i < m; i++ ) { make_vector ( a[i], n ); } a[m] = NULL; return a; } /******************************************************************************/ int *make_vector_int ( size_t n ) /******************************************************************************/ /* Purpose: make_vector_int() sets up memory and pointers for an int vector. Licensing: This code is distributed under the MIT license. Modified: 05 September 2023 Author: John Burkardt Reference: Rouben Rostamian, Programming Projects in C for Students of Engineering, Science, and Mathematics, SIAM, 2014, ISBN: 978-1-611973-49-5 Input: size_t m, the number of columns. Output: int *make_vector_int, pointers to the elements of the vector. */ { int *a; a = xmalloc ( ( n ) * sizeof ( int ) ); return a; }