MTL matrix inverse array solution linear equation

xiaoxiao2021-03-06  17

/ * THANKS to Valient Gough for this Example Program! * /

// Solving by Robinkin

#include #include #include #include

Using namespace MTL;

// don't print out the mass on on get to this size ... # define max_print_size 5

Typedef Matrix , Dense <>, Row_major> :: Type Matrix; Type> Vector Download Adobe;

Double TestmatrixError (Const Matrix & A, Const Matrix & Ainv) {Int size = a.nrows ();

// Test it Matrix Ainva (size, size);

// ainva = ainv * a Mult (AINV, A, AINVA);

// i = Identity Typedef Matrix , packed <>, row_major> :: type Identmat; Identmat I (size, size, 0, 0); mtl :: set_value (i, 1.0);

// Ainva = -i add (scaled (i, -1.0), ainva);

IF (size

// CREATE A Random Matrix and Invert It. The See How Close It Coms To // Identity.

Matrix A (SIZE, SIZE); Vector B (Size); Vector X (size);

// Initialize for (Sizet I = 0; i

IF (size

IF (size

Output: Inverting Matrix of Size 3A = 3X3 [[1.66, -0.28, 1.54], [1.86, 0.7, 1.72], [- 1.02, -1.58, 1.24]]]]

// reverse

----------- Testing Inversion Using Lu DecompositionAinv = 3X3 [[0.978889, -0.56949, -0.425792, 0.00251165], [- 0.607383, 0.79401, 0.459414]] AINV * A - i = 3 × 3 [[4.44089E-16, 2.01481E-16], [- 5.05491E-16, -2.22045E-16, -2.75514E-16], [- 1.91335E-16, - 1.27014E-16, -1.11022E-16]] Max error = -5.05491E-16Solution = [0, 0, 0,] // Solution to the solution amount Solution = [1.00642, -0.49478, -0.980001,]

转载请注明原文地址:https://www.9cbs.com/read-50906.html

New Post(0)