cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

9-Granite

## Element by element division in matrix

Hi Team,
I know it is a long shot. But I hope there is a way to do this. Suppose I have 2 matrix with very different number of rows and columns, say A is M x N and B is L x K. How can I divide each element of A matrix with every element of B matrix and Have it in a form of Matrix.  I am trying few things with nested for loops but have had no luck yet.

1 ACCEPTED SOLUTION

Accepted Solutions
9-Granite
(To:KAL_1625)

I actually found a way to do what I need. But it shows matrix within a matrix with just number of rows and columns. How can I make it to display the entire matrix showing up with values. I have to display each matrix using index.

10 REPLIES 10
24-Ruby V
(To:KAL_1625)

What data structure would you expect as a result? An M x N matrix where each element is an L x K matrix??

You may consider not only to show the two input matrices but, more important, the expected result! And then also attach the worksheet itself.

9-Granite
(To:Werner_E)

@Werner_E Yes I exactly expected what you are saying. A M x N matrix where each element is L x K matrix.

24-Ruby V
(To:KAL_1625)

@KAL_1625 wrote:

@Werner_E Yes I exactly expected what you are saying. A M x N matrix where each element is L x K matrix.

Hmm!!?? But thats quite different from what you answered to ppal where you, too, said that this is exactly what you want the solution to look like!??

Anyway, here is a function which will create this huge result matrix:

With the matrices ppal used:

17-Peridot
(To:KAL_1625)

Like this???

9-Granite
(To:ppal)

This is exactly how I want my solution to look alike, but for some reason, my worksheet is showing error stating that the variable i and j should be scalar or matrix.

9-Granite
(To:KAL_1625)

I actually found a way to do what I need. But it shows matrix within a matrix with just number of rows and columns. How can I make it to display the entire matrix showing up with values. I have to display each matrix using index.

24-Ruby V
(To:KAL_1625)

OK, thats now the third, DIFFERENT display which you claims to be what you are looking for.

In my suggestion the division of an M x N by a L x K matrix results in a M x N matrix (with the elements being L x K matrices).

Your solution here results in a L x K matrix with elements being M x N matrices.

Thats quite different so I wonder what you really are looking for.

Anyway, the reason why the nested matrix is just shown collapsed is because this is the default display in Prime.
You may change it via the menu:

9-Granite
(To:Werner_E)

Thanks, I was not aware of this. thanks for bringing into my attention. To answer your question, the matrix solution that I created up there is what I was looking for. I thought it was very much implied.

24-Ruby V
(To:KAL_1625)

I thought it was very much implied.

Not really IMHO. In a reply to my post you wrote "A M x N matrix where each element is L x K matrix." but finally you were looking for the opposite 😉

BTW, your last but one solution failed because of the wrong usage of the ranges (same applies to ppals solution).
You can display the results generated that way (as ppal has done) but you can't assign the output to a variable or use it later otherwise.
So when writing a program, never use ranges other than the range in a for-loop.

21-Topaz I
(To:KAL_1625)

Hi,

Is this what you intend?

Announcements
Top Tags