Files
mql5-skills/skills/mql5/references/docs/06-matrix/0391-matrix-matrix-solves-matrix-lstsq.md
T
2026-06-23 21:47:51 +08:00

43 lines
869 B
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# LstSq
Return the least-squares solution of linear algebraic equations (for non-square or degenerate matrices).
```
vector matrix::LstSq(
  const vector  b      // ordinate or 'dependent variable' values
   );
```
Parameters
b
[in]  Ordinate or 'dependent variable' values. (Vector of free terms)
Return Value
Vector with solution to the system a * x = b. This is true only for systems that have an exact solution.
Example
```
   matrix a={{3, 2},
             {4,-5},
             {3, 3}};
   vector b={7,40,3};
//---
   vector x=a.LstSq(b);
//--- check, must be [5, -4]
   Print("x=", x);
//--- check, must be [7, 40, 3]
   vector b1=a.MatMul(x);
   Print("b1=",b1);
 
/*
  x=[5.000000000000002,-4]
  b1=[7.000000000000005,40.00000000000001,3.000000000000005]
*/
```