From 400a67fc912b55d27079c5b14238a2193069f280 Mon Sep 17 00:00:00 2001 From: Patrice Matz Date: Sun, 14 Jan 2018 22:34:30 +0100 Subject: [PATCH] =?UTF-8?q?-fixed=20a21=20(gau=C3=9F)=20-added=20a40(1d=20?= =?UTF-8?q?polinomial=20interpolation)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mex/a21.cpp | 3 +- Mex/a40.cpp | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Mex/a40.m | 18 +++++++++++ Mex/a700.cpp | 53 ++++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 Mex/a40.cpp create mode 100644 Mex/a40.m create mode 100644 Mex/a700.cpp diff --git a/Mex/a21.cpp b/Mex/a21.cpp index 905870c..4f3b314 100644 --- a/Mex/a21.cpp +++ b/Mex/a21.cpp @@ -46,11 +46,12 @@ void mexFunction(int nlhs, mxArray *plhs[], // Output variables x[i] = x[i] - GA[i][j] * x[j]; x[i] = x[i] / GA[i][i]; //now finally divide the rhs by the coefficient of the variable to be calculated } - + nlhs = variables; for(int j=0; j < variables; j++){ plhs[j]=mxCreateDoubleScalar(x[j]); } + for (int i = 0; i <= variables; i++ ){ free(GA[i]); } diff --git a/Mex/a40.cpp b/Mex/a40.cpp new file mode 100644 index 0000000..4a5585d --- /dev/null +++ b/Mex/a40.cpp @@ -0,0 +1,91 @@ +#include "mex.h" +#include "matrix.h" +#include "stdlib.h" + +void mexFunction(int nlhs, mxArray *plhs[], // Output variables + int nrhs, const mxArray *prhs[]) // Input variables +{ + int variables = *mxGetPr(prhs[0]); + + double* x = (double *)mxCalloc(variables+1, sizeof(double)); //create solution array + + double** GA = (double **)mxCalloc(variables+1, sizeof(double*)); //create Gauss Array (GA) + for (int i = 0; i <= variables+1; i++){ + GA[i] = (double *)mxCalloc(variables+1, sizeof(double)); + } + + for(int i = 0; i < variables*(variables+1); i++){ //copy input array into GA + GA[i%variables][i/variables] = mxGetPr(prhs[1])[i]; + } + + + int i, j, k; + for (i = 0; i= 0; i--) //back-substitution + { //x is an array whose values correspond to the values of x,y,z.. + x[i] = GA[i][variables]; //make the variable to be calculated equal to the rhs of the last equation + for (j = i + 1; j