Matrix operation library - MetaTrader 5 library | Trading script download - MT4/MT5 resources - MetaTrader 5 resources
This library provides simple matrix operations: addition, subtraction, multiplication, and inversion.
Matrix.mqh must be placed in terminal_data_folder/MQL5/Include/.
Simple example:
Find the inverse matrix of the matrix: F3=((F1+F2)*F2)/10-F2.
F1 and F2 are 3х3 matrices.
#include//+------------------------------------------------------------------+ //|Script program startup function | //+------------------------------------------------------------------+ blank start () { //--- CMatrix *F1; CMatrix *F2; CMatrix *F3; F1= new C matrix ( 3 , 3 ); F2= new C matrix ( 3 , 3 ); F3= new C matrix ( 3 , 3 ); el(F1, 0 , 0 )= 1 ; el(F1, 0 , 1 )= 4 ; el(F1, 0 , 2 )=- 2 ; el(F1, 1 , 0 )=- 3 ; el(F1, 1 , 1 )= 2 ; el(F1, 1 , 2 )= 2 ; el(F1, 2 , 0 )= 1 ; el(F1, 2 , 1 )= 0 ; el(F1, 2 , 2 )=- 2 ; el(F2, 0 , 0 )= 2 ; el(F2, 0 , 1 )= 2 ; el(F2, 0 , 2 )=- 3 ; el(F2, 1 , 0 )=- 1 ; el(F2, 1 , 1 )= 1 ; el(F2, 1 , 2 )= 7 ; el(F2, 2 , 0 )= 3 ; el(F2, 2 , 1 )= 2 ; el(F2, 2 , 2 )= 10 ; F3.add(F1,F2); // F3=F1+F2 F3.Mul(F2); // F3=F3*F2 F3.Mul( 1 ./ 10 ); // F3=F3/10 F3.sub(F2); // F3=F3-F2 double det=F3.Inv(); // Invert the F3 print function ( "det=%5.3f F3[2,2]=%5.3f” ,det,El(F3, 2 , 2 )); Delete F1; Delete F2; Delete F3; }
Expert log output:
det=6.624 F3[2,2]=0.548
Attachment download
📎 matrix.mqh (8.81 KB)
📎matrix_test.mq5 (1.55 KB)
Source: MQL5 #601
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •