Discussion of article "Matrix and Vector operations in MQL5" - page 6

 
Rashid Umarov #:
You need to rest and re-read all your questions in this discussion tomorrow.

Your advice helped, thank you.

But, now I'm still struggling with questions:

1. I need to divide a matrix by a vector - this is a typical task for calculating percentages, when there is a total of each row/column and I need to know the percentage of each cell - very demanded.

   matrixf Test;
   Test.Init(3,2);
   Test.Fill(1);//Fill the matrix with zeros

   vectorf Zero;
   Zero.Init(3);
   Zero.Fill(0);//Fill the matrix with zeros

   Zero=Test/Zero;

I get an error

cannot convert type 'vectorf' to type 'matrixf' Primer_02.mq5   325     11
cannot convert type 'matrixf' to type 'vectorf' Primer_02.mq5   325     10

If you make a matrix from a vector, essentially duplicating columns to restore the size of the matrix over which the calculation is performed, this approach consumes a lot of memory unnecessarily. Pulling vectors out of a matrix in cycles is resource-consuming and seems not rational.

2. Sometimes the divisor is zero, and then we get "-nan(ind)". - but this is not very convenient for further work, maybe there is a possibility to get zero or other forced value in this case, or not to carry out calculation in this cell - by choice?

   matrixf Test;
   Test.Init(3,2);
   Test.Fill(0);//Fill the matrix with zeros

   float z=0;
   Test=Test/z;
   Print(Test);
2022.10.13 06:09:52.125 Primer_02 (EURUSD,H1)   [[-nan(ind),-nan(ind)]
2022.10.13 06:09:52.125 Primer_02 (EURUSD,H1)    [-nan(ind),-nan(ind)]
2022.10.13 06:09:52.125 Primer_02 (EURUSD,H1)    [-nan(ind),-nan(ind)]]
 
Aleksey Vyazmikin #:

Your advice helped, thank you.

But now I'm still wondering:

1. I need to divide a matrix by a vector - this is a typical task for calculating percentages, when there is a total sum of each row/column and I need to know the percentage of each cell - very demanded.

I get an error


You have a desire to break everything. Go further yourself, I won't help you any more - it hurts to look at the examples

//+------------------------------------------------------------------+
//| Script programme start function|
//+------------------------------------------------------------------+
void OnStart()
 {
//---
   matrixf m;
   m.Init(3,2);
   m.Fill(7);//Fill the matrix with NON-ZEROs

   vectorf divider;
   divider.Init(2);
   divider.Fill(3);//Fill the vector with NONE zeros

   for(ulong i=0;i<m.Rows();i++)
     {
      m.Row(m.Row(i)/divider,i);
     }
   Print(m);  
 }
 
Rashid Umarov #:

You have a desire to break everything. You can take it from here, I won't help you any further, it hurts to see examples of this.

I guess the syntax doesn't go)))))

 
Rashid Umarov #:

You have a desire to break everything. You can take it from here, I won't help you any further, it hurts to see examples of this.

So do it more reliably :)))))))

The example is wrong, I need to divide each column of the matrix by the corresponding value in the row of the vector. That is, the vector should represent a column, not a row. I understand that then I need to transpose the matrix..... I thought it was possible without a loop.

And, I am of course very interested in the answer to the second question. Not even an answer, but rather adding a possibility to put a zero in the final matrix when dividing by zero.

 
The man has already broken the catbusters, soon there will be nothing left of the matrices )
 
Maxim Dmitrievsky #:
The man has already broken the catbuster, soon there will be nothing left of the matrices )

By throwing in false information, you strengthen the statement of a respected person on this resource, apparently trying to attach to his authority and make me in a bad light,

Do you have a personal grudge?

 
Aleksey Vyazmikin #:

By throwing in false information, you amplify the statement of a respected person on this resource, apparently trying to attach yourself to his authority and make me look bad,

Do you have a personal grudge?

I don't think humour has been banned yet.

 
Maxim Dmitrievsky #:

I don't think they've banned humour yet.

It's probably funny. I can even surmise the real premise of the statement. However, few people will understand what we are talking about, if they are not regulars of the MoD thread.

Do you understand the new syntax of matrices, and am I the only one who is so bad at thinking?

 
Aleksey Vyazmikin #:

Maybe it's funny. I can even surmise the real premise of the statement. However, few people will understand what it is about unless they are regulars in the MoD thread.

Do you understand the new syntax of matrices, and am I the only one who is so bad at thinking?

I haven't read it, it's implemented differently everywhere, you just have to look at the peculiarities.

I think everything is clear, I use dataframes in python myself, it has its own specifics.

 

Please clarify how to copy a column from one matrix to another!

I don't understand the example through copy to vector.

vector matrix::Col(
  const ulong   ncol      // column number
   );
 
void matrix::Col(
  const vector  v,        // column vector
  const ulong   ncol      // column number
   );

Here is a piece of my code

   for(P=0; P<Type_Q_Perebor; P++)
   {
      matrixf m_Data_calc;//Matrix with table for calculations
      vectorf V_Data_calc;//Vector for array to matrix transfer
      switch(P)
      {
      case 0:
         m_Data_calc.Init(Strok_Total_Data*N_1, 1);//Initialise the matrix
         m_Data.Reshape(Strok_Total_Data, Stolb_Total_Data);//Improve the matrix size with the data
         break;
      case 1:
         m_Data_calc.Init(Strok_Total_Data*N_0, 1);//Initialise the matrix
         m_Data.Reshape(Strok_Total_Data, Stolb_Total_Data);//Improve the matrix size with the data
         break;
      }

      V_Data_calc.Cov(m_Data_calc,0);//Copy the column vector from the matrix
      m_Data_calc.Col(V_Data_calc,0);//Copy the column vector into the matrix
   }

I get an error

'Cov' - wrong parameters count  Tree_Analiz_Bi_V_2_4.mq5        219     19
   built-in: matrixf vectorf:Cov(const vectorf&)        Tree_Analiz_Bi_V_2_4.mq5        219     19