Linear Algebra in C++ - Part 2c - Compute matrix inverse (Testing with Python)

preview_player
Показать описание
Linear Algebra in C++ - Part 2c - Compute matrix inverse (Testing with Python)

Linear algebra is essential to most scientific computing and fields of engineering, including #machinelearning. Matrices and matrix arithmetic are a fundamental part of linear algebra and so being able to handle matrices in C++ can be extremely useful. Inverting a matrix is a fundamental operation in linear algebra and is definitely something that our matrix class should support. In this video I cover how I have approached testing the new Inverse() function for the qbMatrix2 class using Python to create a CSV file containing a large number of matrices and their 'gold-standard' inverses computed using the Numpy library. I then cover how I have implemented code in C++ to read in this CSV file, compute the inverse of each matrix using my Gauss-Jordan elimination algorithm and then compare this result with the gold standard.

**********************************
You can also follow me on the QuantitativeBytes Facebook page at:

**********************************

Part 1 of the series, where I introduce the code for a simple class to handle matrices in C++ can be seen here:

Part 2a of the series, where I cover the theory behind the Gauss-Jordan elimination method can be seen here:

Part 2b of the series, where I go over how I have approached implementing the Gauss-Jordan elimination method in C++ can be seen here:

Part 3 of the series covering how to compute the determinant of an NxN square matrix may be seen here:

Part 4 of the series covering implementation of a simple vector class may be seen here:

Part 5 - Compute the vector norm and handle multiplication of a matrix by a vector:

**********

The particular matrix that I talk about that seems to be an interesting case is here, as promised, in CSV format so you can copy and paste into other software if you want to have a go at inverting it yourself.

-7.06711357635508,2.86204331759976,8.72551512419021,-3.49596266237113,1.09637006931382
2.29334230427082,-8.86162756725844,-5.53715539554703,-7.73341321854147,8.0623899548081
-7.06854274385278,-8.29455270479789,8.44531043955609,4.84975158392336,-8.9356105292099
4.54902139094058,6.89377456364728,3.57467196456786,-2.29115216667741,-6.82361882016302
-3.23314126063932,5.03687573600115,-7.7412062869873,-0.455529780242026,-6.0503439372704

**********

As with all of my videos, I show the code that I have developed to solve the particular problems that I need to solve, with the hope that it may provide sufficient background and inspiration to allow you to go on to develop your own code if you wish to. My code may not be the most appropriate solution to the problem you are trying to solve, so I urge you to consider the problem carefully and decide for yourself on the most appropriate solution. I make every effort to ensure that my code works as it should and is free of bugs, but of course I cannot provide any guarantees. If you use my code as shown, I strongly encourage you to make sure that you test it thoroughly to ensure that it works as you need it to. If you find a bug, do please let me know in the comments!
Рекомендации по теме
Комментарии
Автор

Hello. Could you provide the test.csv and testFP.csv data to your github, as well?

evgenytarasov
join shbcf.ru