first commit (gaussjordan is bugged)
This commit is contained in:
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Xmake cache
|
||||||
|
.xmake/
|
||||||
|
build/
|
||||||
|
|
||||||
|
# MacOS Cache
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
|
||||||
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "xmake",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug XMake target",
|
||||||
|
"target": "Pivot",
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"stopAtEntry": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
49
.vscode/settings.json
vendored
Normal file
49
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"array": "cpp",
|
||||||
|
"atomic": "cpp",
|
||||||
|
"bit": "cpp",
|
||||||
|
"*.tcc": "cpp",
|
||||||
|
"cctype": "cpp",
|
||||||
|
"clocale": "cpp",
|
||||||
|
"cmath": "cpp",
|
||||||
|
"compare": "cpp",
|
||||||
|
"concepts": "cpp",
|
||||||
|
"cstdarg": "cpp",
|
||||||
|
"cstddef": "cpp",
|
||||||
|
"cstdint": "cpp",
|
||||||
|
"cstdio": "cpp",
|
||||||
|
"cstdlib": "cpp",
|
||||||
|
"cwchar": "cpp",
|
||||||
|
"cwctype": "cpp",
|
||||||
|
"deque": "cpp",
|
||||||
|
"string": "cpp",
|
||||||
|
"unordered_map": "cpp",
|
||||||
|
"vector": "cpp",
|
||||||
|
"exception": "cpp",
|
||||||
|
"algorithm": "cpp",
|
||||||
|
"functional": "cpp",
|
||||||
|
"iterator": "cpp",
|
||||||
|
"memory": "cpp",
|
||||||
|
"memory_resource": "cpp",
|
||||||
|
"numeric": "cpp",
|
||||||
|
"random": "cpp",
|
||||||
|
"string_view": "cpp",
|
||||||
|
"system_error": "cpp",
|
||||||
|
"tuple": "cpp",
|
||||||
|
"type_traits": "cpp",
|
||||||
|
"utility": "cpp",
|
||||||
|
"initializer_list": "cpp",
|
||||||
|
"iosfwd": "cpp",
|
||||||
|
"iostream": "cpp",
|
||||||
|
"istream": "cpp",
|
||||||
|
"limits": "cpp",
|
||||||
|
"new": "cpp",
|
||||||
|
"numbers": "cpp",
|
||||||
|
"ostream": "cpp",
|
||||||
|
"stdexcept": "cpp",
|
||||||
|
"streambuf": "cpp",
|
||||||
|
"cinttypes": "cpp",
|
||||||
|
"typeinfo": "cpp"
|
||||||
|
}
|
||||||
|
}
|
||||||
28
.vscode/tasks.json
vendored
Normal file
28
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"type": "cppbuild",
|
||||||
|
"label": "C/C++: gcc build active file",
|
||||||
|
"command": "/usr/bin/gcc",
|
||||||
|
"args": [
|
||||||
|
"-fdiagnostics-color=always",
|
||||||
|
"-g",
|
||||||
|
"${file}",
|
||||||
|
"-o",
|
||||||
|
"${fileDirname}/${fileBasenameNoExtension}"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${fileDirname}"
|
||||||
|
},
|
||||||
|
"problemMatcher": [
|
||||||
|
"$gcc"
|
||||||
|
],
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
},
|
||||||
|
"detail": "Task generated by Debugger."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": "2.0.0"
|
||||||
|
}
|
||||||
164
src/main.cpp
Normal file
164
src/main.cpp
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Matrix
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::size_t m_Lignes;
|
||||||
|
std::size_t m_Colonnes;
|
||||||
|
std::size_t m_Dimension;
|
||||||
|
std::vector<T> m_Data;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Matrix(std::size_t lignes, std::size_t colonnes) : m_Lignes(lignes), m_Colonnes(colonnes), m_Dimension(lignes * colonnes)
|
||||||
|
{
|
||||||
|
m_Data.resize(m_Dimension);
|
||||||
|
}
|
||||||
|
~Matrix() {}
|
||||||
|
|
||||||
|
void Print() const
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < m_Lignes; ++i)
|
||||||
|
{
|
||||||
|
std::cout << "[ ";
|
||||||
|
for (size_t j = 0; j < m_Colonnes; ++j)
|
||||||
|
{
|
||||||
|
std::size_t indice = i * m_Lignes + j;
|
||||||
|
std::cout << at(i, j) << " ";
|
||||||
|
}
|
||||||
|
std::cout << "]";
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Insert()
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < m_Lignes; ++i)
|
||||||
|
{
|
||||||
|
for (size_t j = 0; j < m_Colonnes; ++j)
|
||||||
|
{
|
||||||
|
std::cin >> at(i, j);
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DivideLine(T div, std::size_t line){
|
||||||
|
for (size_t i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
/* code */
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GaussJordan()
|
||||||
|
{
|
||||||
|
int r = -1;
|
||||||
|
for (std::size_t j = 0; j < m_Colonnes; ++j)
|
||||||
|
{
|
||||||
|
std::size_t k = 0;
|
||||||
|
// Rechercher
|
||||||
|
for (std::size_t i = r + 1; i < m_Lignes; ++i)
|
||||||
|
{
|
||||||
|
if (at(i, j) > at(k, j))
|
||||||
|
{
|
||||||
|
k = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Matrix<float> mat_pivot(1, 1);
|
||||||
|
mat_pivot.at(0, 0) = at(k, j);
|
||||||
|
if (at(k, j) != 0)
|
||||||
|
{
|
||||||
|
++r;
|
||||||
|
// Diviser
|
||||||
|
for (std::size_t z = 0; z < m_Colonnes; ++z)
|
||||||
|
{
|
||||||
|
at(k, z) /= mat_pivot.at(0, 0);
|
||||||
|
}
|
||||||
|
if (k != r)
|
||||||
|
{
|
||||||
|
// Echanger
|
||||||
|
for (std::size_t z = 0; z < m_Colonnes; ++z)
|
||||||
|
{
|
||||||
|
std::swap(at(k, z), at(r, z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (std::size_t i = 0; i < m_Lignes; ++i)
|
||||||
|
{
|
||||||
|
if (i != r)
|
||||||
|
{
|
||||||
|
//Soustraire
|
||||||
|
for (std::size_t z = 0; z < m_Colonnes; ++z)
|
||||||
|
{
|
||||||
|
at(i, z) -= at(r, z) * at(i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
T &operator[](std::size_t indice)
|
||||||
|
{
|
||||||
|
return at(indice);
|
||||||
|
}
|
||||||
|
|
||||||
|
T &at(std::size_t ligne, std::size_t colonne)
|
||||||
|
{
|
||||||
|
return m_Data[ligne * m_Lignes + colonne];
|
||||||
|
}
|
||||||
|
|
||||||
|
T at(std::size_t ligne, std::size_t colonne) const
|
||||||
|
{
|
||||||
|
return m_Data[ligne * m_Lignes + colonne];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*std::vector<T>::iterator begin() {
|
||||||
|
return m_Data.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<T>::iterator end() {
|
||||||
|
return m_Data.end();
|
||||||
|
}*/
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
void test()
|
||||||
|
{
|
||||||
|
Matrix<float> mat(2, 2);
|
||||||
|
mat.at(0, 0) = 4;
|
||||||
|
mat.at(0, 1) = 3;
|
||||||
|
mat.at(1, 0) = 2;
|
||||||
|
mat.at(1, 1) = 1;
|
||||||
|
|
||||||
|
mat.Print();
|
||||||
|
mat.GaussJordan();
|
||||||
|
mat.Print();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
//test();
|
||||||
|
|
||||||
|
std::cout << "hello world!" << std::endl;
|
||||||
|
std::cout << "Quelle est le nombre de lignes de votre matrice ?" << std::endl;
|
||||||
|
std::size_t lignes;
|
||||||
|
std::cin >> lignes;
|
||||||
|
std::cout << "Quelle est le nombre de colonnes de votre matrice ?" << std::endl;
|
||||||
|
std::size_t colonnes;
|
||||||
|
std::cin >> colonnes;
|
||||||
|
std::size_t dimension = lignes * colonnes;
|
||||||
|
std::cout << "Rentrez les coefficients de la matrice" << std::endl;
|
||||||
|
Matrix<float> mat(lignes, colonnes);
|
||||||
|
|
||||||
|
mat.Insert();
|
||||||
|
|
||||||
|
mat.Print();
|
||||||
|
mat.GaussJordan();
|
||||||
|
std::cout << std::endl;
|
||||||
|
mat.Print();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
75
xmake.lua
Normal file
75
xmake.lua
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
add_rules("mode.debug", "mode.release")
|
||||||
|
|
||||||
|
target("Pivot")
|
||||||
|
set_kind("binary")
|
||||||
|
add_files("src/*.cpp")
|
||||||
|
|
||||||
|
--
|
||||||
|
-- If you want to known more usage about xmake, please see https://xmake.io
|
||||||
|
--
|
||||||
|
-- ## FAQ
|
||||||
|
--
|
||||||
|
-- You can enter the project directory firstly before building project.
|
||||||
|
--
|
||||||
|
-- $ cd projectdir
|
||||||
|
--
|
||||||
|
-- 1. How to build project?
|
||||||
|
--
|
||||||
|
-- $ xmake
|
||||||
|
--
|
||||||
|
-- 2. How to configure project?
|
||||||
|
--
|
||||||
|
-- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release]
|
||||||
|
--
|
||||||
|
-- 3. Where is the build output directory?
|
||||||
|
--
|
||||||
|
-- The default output directory is `./build` and you can configure the output directory.
|
||||||
|
--
|
||||||
|
-- $ xmake f -o outputdir
|
||||||
|
-- $ xmake
|
||||||
|
--
|
||||||
|
-- 4. How to run and debug target after building project?
|
||||||
|
--
|
||||||
|
-- $ xmake run [targetname]
|
||||||
|
-- $ xmake run -d [targetname]
|
||||||
|
--
|
||||||
|
-- 5. How to install target to the system directory or other output directory?
|
||||||
|
--
|
||||||
|
-- $ xmake install
|
||||||
|
-- $ xmake install -o installdir
|
||||||
|
--
|
||||||
|
-- 6. Add some frequently-used compilation flags in xmake.lua
|
||||||
|
--
|
||||||
|
-- @code
|
||||||
|
-- -- add debug and release modes
|
||||||
|
-- add_rules("mode.debug", "mode.release")
|
||||||
|
--
|
||||||
|
-- -- add macro definition
|
||||||
|
-- add_defines("NDEBUG", "_GNU_SOURCE=1")
|
||||||
|
--
|
||||||
|
-- -- set warning all as error
|
||||||
|
-- set_warnings("all", "error")
|
||||||
|
--
|
||||||
|
-- -- set language: c99, c++11
|
||||||
|
-- set_languages("c99", "c++11")
|
||||||
|
--
|
||||||
|
-- -- set optimization: none, faster, fastest, smallest
|
||||||
|
-- set_optimize("fastest")
|
||||||
|
--
|
||||||
|
-- -- add include search directories
|
||||||
|
-- add_includedirs("/usr/include", "/usr/local/include")
|
||||||
|
--
|
||||||
|
-- -- add link libraries and search directories
|
||||||
|
-- add_links("tbox")
|
||||||
|
-- add_linkdirs("/usr/local/lib", "/usr/lib")
|
||||||
|
--
|
||||||
|
-- -- add system link libraries
|
||||||
|
-- add_syslinks("z", "pthread")
|
||||||
|
--
|
||||||
|
-- -- add compilation and link flags
|
||||||
|
-- add_cxflags("-stdnolib", "-fno-strict-aliasing")
|
||||||
|
-- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true})
|
||||||
|
--
|
||||||
|
-- @endcode
|
||||||
|
--
|
||||||
|
|
||||||
Reference in New Issue
Block a user