Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

max value between many matrix

Status
Not open for further replies.

Salvanto

Systems Engineer
Oct 12, 2018
9
IT
Hello, i have a problem to find the maximum value between many array.
I do a "cicle do", and i found 2718 array. I would like to find the maximum value between this 2718 array.
This is one part of the code:
do i=2, 5436, 2
y = Matmul (Om,y) + Matmul (g0, Vm)*H(2,i)+Matmul(g0, Vm)*H(2,i+2)
end do

obviously y assumed 2718 different values in the arrays.
Sorry for my english.
Thx in advance.
 
As I understood, you compute the array y in a loop 2718 times.
Sorry, but I didn't understand what you want to find:
1. a maximum array of all the computed arrays, i.e. one array of the 2718 arrays with the maximum norm ||y||
or
2. one maximum element y(k) of all the 2718 arrays computed
?
 
Thx for the Answer.
2. one maximum element y(k) of all the 2718 arrays computed
The matrix have this dimension (2,1). I want to find the maximum element y(1,1) of all the 2718 arrays computed between all the 2718 arrays computed.
 
Salvanto said:
I want to find the maximum element y(1,1) of all the 2718 arrays computed between all the 2718 arrays computed.

If you need the maximum of all values y(1,1) computed in 2718 steps you can enhance the loop with a simple maximum computation like this:
Code:
my_max = 0 ! or if y(1,1) could be negative then the lowest value
do i=2, 5436, 2
  y = Matmul (Om,y) + Matmul (g0, Vm)*H(2,i)+Matmul(g0, Vm)*H(2,i+2)
  ! get the maximum value of y(1,1)
  if (y(1,1) > my_max) then
    my_max = y(1,1)
  end if  
end do
write(*,*) 'my_max = ', my_max

or if you think that you will need all the values of y(1,1) after the loop for other research you can rather store them first in a separate array and then find the maximum of this array - for example like this:
Code:
! first declare the array my_values of the dimension 2718
j = 0
do i=2, 5436, 2
  y = Matmul (Om,y) + Matmul (g0, Vm)*H(2,i)+Matmul(g0, Vm)*H(2,i+2)
  ! store the value of y(1,1) into the array my_values
  j = j + 1
  my_values(j) = y(1,1)
end do
! get the maximum value of my_values
my_max = my_values(1)
do j=2, 2718
  if (my_values(j) > my_max) then
    my_max = my_values(j)
  end if  
end do
write(*,*) 'my_max = ', my_max

 
Yes thx!!!I have another question!!

But if instead, always from the following expression:

do i=2, 5436, 2
y = Matmul (Om,y) + Matmul (g0, Vm)*H(2,i)+Matmul(g0, Vm)*H(2,i+2)

I would like that in the matrix product "Om * y", the "y" was the one obtained in the previous calculation. I'll explain better, I give the initial conditions of "y", ie y (1,1) = 0 and y (2,1) = 0 and calculate the value of "y" with the previously written expression. In practice I would like to calculate the first value of "y" with those boundary conditions, the second value of "y" according to the value obtained from the first value of "y" and so on.
 
It seems that you already do it that way:
Before the loop you have y=y0
the in the first iteration for i = 2 you will get from the computation y = Matmul (Om,y) + ...
the new value i.e. y1 = Matmul (Om,y0) + ...
in the second iteration for i = 4 you will get from the computation y = Matmul (Om,y) + ...
then new value y2 = Matmul (Om,y1) + ..
... etc ...

If you are unsure prove it, printing the value of the array y in some iterations or inspect it in the debugger.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top