Discussion of article "Matrices and vectors in MQL5"

 

New article Matrices and vectors in MQL5 has been published:

By using special data types 'matrix' and 'vector', it is possible to create code which is very close to mathematical notation. With these methods, you can avoid the need to create nested loops or to mind correct indexing of arrays in calculations. Therefore, the use of matrix and vector methods increases the reliability and speed in developing complex programs.

Collections of ordered data, wherein all elements have the same type, are usually operated through Arrays, in which each element can be accessed by its index. Arrays are widely used in solving various linear algebra problems, in mathematical modeling tasks, in machine learning, etc. In general terms, the solution of such problems is based on mathematical operations using matrices and vectors, with which very complex transformations can be compactly written in the form of simple formulas. Programming of such operations requires good knowledge in mathematics along with the ability to write complex nested loops. Debugging and bug fixing in such programs can be quite challenging. 

By using special data types 'matrix' and 'vector', it is possible to create the code which is very close to mathematical notation while avoiding the need to create nested loops or to mind correct indexing of arrays in calculations. In this article, we will see how to create, initialize, and use matrix and vector objects in MQL5.

Author: MetaQuotes

MetaQuotes
  • 2022.02.11
  • www.mql5.com
Trader's profile
 
MetaQuotes:

New article Matrices and Vectors in MQL5 has been published:

Author: MetaQuotes

Welcome to exchange investment philosophy with me, micro-signal: hgb2022168

 

Hello, why in C++a vector is created without a specified length, but in MQL5 it is necessary to specify the vector length ?

For example, in C++ it works:

vector <int> vector_second;
 for (int i = 0; i < 3; i++) {
     vector_second .push_back(i);

  }

в  MQL5  не работает:

int value ;  

   vector v;

for(int i = 0; i < 11; i++)

     {

     value =i;

    v[i]=value;

     }

Print("v = ", v);


in MQL5 works:


int value ;  

   vector v(11);

for(int i = 0; i < 11; i++)

     {

     value =i;

    v[i]=value;

     }

Print("v = ", v);

[Deleted]  
knyazeff.vad #:

Hello, why in C++a vector is created without a specified length, but in MQL5 it is necessary to specify the vector length ?

For example, in C++ it works:



in MQL5 works:


The push_back() function in C++ adds an element to a vector. So it doesn't care if it is empty or not.

Try to write the same as in MQL instead of it:

vector_second[i] = i;

You will also get an error.

 
Koldun Zloy #:

The push_back() function in C++ adds an element to a vector, so it doesn't care whether it is empty or not.

Try to write the same as in MQL instead:

You will also get an error.

Will a function like push_back () and a description of working with string functions in vectors be added to MQL 5 ?

 
Will a function like push_back () and description of working with string functions in vectorsbe added toMQL 5 ?
 
Greetings, please supplement the MQL5 Reference Manual with examples etc. on matrices and vectors, that they can be passed by matrix& reference, etc.
 
Got to external I/O, are file operations on vectors/matrices planned? FileWrite/ReadMatrix will be?
 
Mikhail Mishanin #:
Got to external I/O, are file operations on vectors/matrices planned? FileWrite/ReadMatrix will there be?
FileWriteStruct does not work?
 
Aliaksandr Hryshyn #:
FileWriteStruct does not work?

No attempts so far, the question is just how vector columns and vector rows will be written/read, and matrices of course.

I will get to coding today and will report the result.