From bcdf5da197200dc704853b7db2f2caa649898994 Mon Sep 17 00:00:00 2001 From: Patrice Matz Date: Tue, 31 Oct 2017 22:27:55 +0100 Subject: [PATCH] - added fucntion to calc. det of nxn matrix --- SCE/SCE/SCE.cpp | 6 ++++-- SCE/SCE/lgs.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++-- SCE/SCE/lgs.h | 4 +++- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/SCE/SCE/SCE.cpp b/SCE/SCE/SCE.cpp index 8623562..1a82901 100644 --- a/SCE/SCE/SCE.cpp +++ b/SCE/SCE/SCE.cpp @@ -39,6 +39,8 @@ void cylinder() void lgs() { LGS lgs; - //lgs.data_entry(); - lgs.gauss(); + lgs.data_entry(); + //lgs.gauss(); + lgs.cramer(); + cout << endl; } diff --git a/SCE/SCE/lgs.cpp b/SCE/SCE/lgs.cpp index 5380e13..df5fc05 100644 --- a/SCE/SCE/lgs.cpp +++ b/SCE/SCE/lgs.cpp @@ -11,7 +11,7 @@ void LGS::data_entry() while (auswahl == 'n') { cout << "Anzahl der Unbekannten: "; cin >> variables; - creat_array(); + create_array(); cout << "Geben Sie die Gleichungen nach folgendem Schema an:" << endl; print_exp(); @@ -35,7 +35,7 @@ void LGS::data_entry() cout << endl; } -void LGS::creat_array() +void LGS::create_array() { x = new long double[variables]; GA = new long double*[variables]; @@ -138,5 +138,46 @@ float LGS::cramer() { double t1 = clock(); + long double det1 = determinant(GA,variables); + cout << det1; + return (float)((clock() - t1) / CLOCKS_PER_SEC); +} + +long double LGS::determinant(long double** ga, int m) +{ + + long double sum = 0; + long double** t = new long double*[variables]; + for (int i = 0; i < variables; ++i) + t[i] = new long double[variables]; + + if (m == 2) + { + sum = ga[0][0] * ga[1][1] - ga[0][1] * ga[1][0]; + return sum; + } + for (int p = 0; p