// myMatrix.h
typedef struct {
double** at;
int rows, cols;
}Matrix;
// Create Matrix with specified size
extern Matrix createMat(int _rows, int _cols);
// Free a memory allocated matrix
extern void freeMat(Matrix _A);
// Create a matrix from a text file
extern Matrix txt2Mat(std::string _filePath, std::string _fileName);
//// Print matrix
extern void printMat(Matrix _A, const char* _name);
// Matrix addition
extern Matrix addMat(Matrix _A, Matrix _B);
// ....
Example Code
/*==========================================================================*/
/* Variables declaration & initialization */
/*--------------------------------------------------------------------------*/
// Option 1: Read from datafile
Matrix matA = txt2Mat(path, "prob1_matA");
Matrix vecb = txt2Mat(path, "prob1_vecb");
// Option 2: Create an empty Matrix or Vector
int rows = 4;
int cols = 4;
Matrix matC = createMat(rows, cols);
// Option 3: Create a zero matrix with specific size
Matrix matD = zeros(matA.rows, matA.cols);
/*==========================================================================*/
/* Accessing, modifying Matrix */
/*--------------------------------------------------------------------------*/
// Example: Accessing each element in Matrix
for (int i = 0; i < matA.rows; i++)
for (int j = 0; j < matA.cols; j++)
matC.at[i][j] = matA.at[i][j];
printMat(matA, "matA");
// Exmaple: Applying your NP algorithm
Matrix matAdd = addMat(matA, matC);
printMat(matAdd, "matU + matA");
/*==========================================================================*/
/* Deallocate memory */
/*==========================================================================*/
freeMat(matA); freeMat(vecb);
What to change for Assignment
Initially, change the assignment number for #define ASGN
DO NOT modify other code lines
#include "myMatrix.h"
#define ASGN 999 // enter your assignment number
#define EVAL 0 // [※ DO NOT EDIT !!!]
int main(int argc, char* argv[])
{
/* [※ DO NOT EDIT !!!] Resources file path setting for evaluation */
//std::string path = "C:/NP_Data/Assignment" + std::to_string(ASGN) + "/";
std::string path = "../../NP_Data/Assignment" + std::to_string(ASGN) + "/";
#if EVAL
path += "eval/";
#endif
...
Read data text files. You must use the given file names.
Then, apply your numerical programming algorithm.
/*==========================================================================*/
/* Variables declaration & initialization */
/*--------------------------------------------------------------------------*/
/* - You can change the variable names */
/* - However, you must use the specified txt file name */
/*==========================================================================*/
Matrix matA = txt2Mat(path, "prob1_matA");
Matrix vecb = txt2Mat(path, "prob1_vecb");
Matrix matU = txt2Mat(path, "prob1_matU");
Matrix vecd = txt2Mat(path, "prob1_vecd");
Matrix vecx_true = txt2Mat(path, "prob1_vecx_true");
// Your Code goes Here
// Your Code goes Here
/*==========================================================================*/
/* Apply your numerical method algorithm */
/*==========================================================================*/
Matrix matAdd = addMat(matA, matU); // example code
// Your Code goes Here
// Your Code goes Here
// ...
Prints vector or matrix results. You have to give a brief description for each print.