Dear Friends, I have a programming problem which seems to be a case for If/For functions but I am not able to formulate it properly. Attached file contains a simplified script which is my first thought, but it can work only if somehow I find a way to pick the elements of a matrix in increasing numerical values. I could not think of a way out, will appreciate any suggestion on it. Following is the short description of the problem. Thanks
I have two 6 X 6 matrix G and A having elements to be a function of integer m having values 0 - 5. At the beginning of loop m = 0.
G[m_] = {{g11, g12, g13, g14, g15 g16},
., {g21, g22, g23,
g56, g66}}
A[m_] = {{a11, a12, a13, a14, a15 a16},
., {a21, a22, a23,
a56, a66}}
There is another six elements row matrix
H[m_] = {h1, h2, h3, h4, h5, h6}
Now I want to perform a loop operation on the system such that elements of matrix G in the order of increasing numerical values are compared with the corresponding elements of A such that if for the element [i, j]
If g[i j] < A[i, j] -> next higher magnitude g[i, j] is selected
Or if g[i j] > A[i, j] -> m increases by 1 (m++) and hence H[m] -> H[m++], where
H[m++] = ReplacePart[H[m], {j-> hj+hi, i-> 0]
Now for new value of m, G and A will have new elements and cycle will continue till m = 5, and at this point one element of H[5] matrix would be h1+h2+h3+h4+h5+h6 with all others to be zero.
Attachments: