From 4d9fc9de8a8afc82b4e02c2433e7139be8fc45d1 Mon Sep 17 00:00:00 2001 From: Patrice Matz Date: Thu, 4 Jan 2018 22:53:27 +0100 Subject: [PATCH] - added 2.2 cramer --- Mex/a22.cpp | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 Mex/a22.cpp diff --git a/Mex/a22.cpp b/Mex/a22.cpp new file mode 100644 index 0000000..792685c --- /dev/null +++ b/Mex/a22.cpp @@ -0,0 +1,120 @@ +#include "mex.h" +#include "matrix.h" +#include "stdlib.h" + + +double** CA; +double** CA2; +double* x; +int variables; + + +void copy_array() +{ + for (int i = 0; i < variables; ++i) + for (int n = 0; n < variables + 1; ++n) + CA2[i][n] = CA[i][n]; +} + +void swap_column(double** ca2, int col) +{ + double* temp = (double *)mxCalloc(variables, sizeof(double)); + copy_array(); + for(int i=0; i < variables ;i++) + { + temp[i] = CA[i][variables]; + } + for(int i=0; i < variables ;i++) + { + CA2[i][col] = temp[i]; + } + free(temp); +} + +double determinant(double** ga, int m) +{ + + double sum = 0; + double** t = (double **)mxCalloc(variables, sizeof(double*)); + for (int i = 0; i < variables; ++i) + t[i] = (double *)mxCalloc(variables, sizeof(double)); + + + if (m == 2) + { + sum = ga[0][0] * ga[1][1] - ga[0][1] * ga[1][0]; + return sum; + } + for (int p = 0; p