// myMatrix.htypedefstruct { double** at;int rows, cols;}Matrix;// Create Matrix with specified sizeexternMatrixcreateMat(int _rows,int _cols);// Free a memory allocated matrixexternvoidfreeMat(Matrix _A);// Create a matrix from a text fileexternMatrixtxt2Mat(std::string _filePath, std::string _fileName);//// Print matrixexternvoidprintMat(Matrix _A,constchar* _name);// Matrix additionexternMatrixaddMat(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 Vectorint 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 Matrixfor (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"#defineASGN999 // enter your assignment number#defineEVAL0 // [※ DO NOT EDIT !!!]intmain(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) +"/";#ifEVAL 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.