Multiplying multiple renamed matrices

In summary, the issue at hand is the multiplication of 'n' number of matrices that are output from a for loop within a for loop. One solution is to use a for loop and the dot product operator to multiply the matrices together in the desired order and store the result in a total_matrix variable.
  • #1
jono05
1
0
I have a problem multiplying 'n' number of matrices which are output from a for loop within a for loop.

I am using the code "eval(['matrix' num2str(t) '= [A,B;C,D]')] to each matrix with their respective frequency number (t) on the end and then repeat the loop. i.e if there was frequency from 1-3 it would output
matrix1=[values of A,B,C,D at that frequency]
matrix2=[ ]
matrix3=[ ] ect

These matrix(t) then have to all be multiplied together to create a transfer matrix which is also 2X2 i.e matrix1*matrix2*matrix3.

can anyone tell me how to word this so i can get the output after the loop to multiply from matrix(1) to matrix(t) together? The variables are not stored in numerical order meaning an array is not possible.
Anyone got any ideas? if I'm not wording this clearly enough please say and i'll try to be mo precise.

thanks.
 
Physics news on Phys.org
  • #2
One possible solution would be to use a for loop to iterate through each matrix and then use the dot product operator (.*) to multiply them together. For example:total_matrix = matrix1;for t = 2:n total_matrix = total_matrix.*matrix(t);endThis will multiply all of the matrices together in the order they are given and then store the result in total_matrix.
 
  • #3


I would suggest breaking down the problem into smaller steps and clearly defining your variables. It seems like you have a for loop within a for loop, which can make the code more complex and difficult to understand. Instead, you could try creating a single for loop that iterates through all the matrices and multiplies them together.

Additionally, it might be helpful to store the matrices in an array or data structure, rather than using a variable with a frequency number at the end. This would make it easier to access and manipulate the matrices in your code.

Lastly, make sure to clearly define your desired output and any constraints or limitations you may have. This will help others understand your problem and provide more specific solutions.
 

1. What is the purpose of multiplying multiple renamed matrices?

The purpose of multiplying multiple renamed matrices is to perform mathematical operations on multiple matrices simultaneously in order to obtain a final matrix that represents the combined effects of the individual matrices.

2. How do I determine the order of multiplication for multiple renamed matrices?

The order of multiplication for multiple renamed matrices is determined by the associative property, which states that the order of multiplication does not affect the final result. Therefore, the matrices can be multiplied in any order as long as the dimensions are compatible.

3. What are the dimensions of the resulting matrix when multiplying multiple renamed matrices?

The dimensions of the resulting matrix when multiplying multiple renamed matrices will depend on the dimensions of the individual matrices being multiplied. The number of rows in the first matrix must be equal to the number of columns in the second matrix in order for the multiplication to be possible.

4. Can I multiply more than two matrices at a time?

Yes, it is possible to multiply more than two matrices at a time. However, the order of multiplication may affect the final result, so it is important to carefully consider the order in which the matrices are multiplied.

5. How can I check if the dimensions of the matrices are compatible for multiplication?

You can check if the dimensions of the matrices are compatible for multiplication by ensuring that the number of columns in the first matrix is equal to the number of rows in the second matrix. Additionally, the resulting matrix will have the same number of rows as the first matrix and the same number of columns as the second matrix.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
5K
Replies
2
Views
16K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
6K
Replies
4
Views
3K
  • Programming and Computer Science
Replies
8
Views
2K
  • Calculus and Beyond Homework Help
Replies
11
Views
3K
  • Programming and Computer Science
Replies
31
Views
2K
  • Linear and Abstract Algebra
Replies
8
Views
2K
  • Calculus and Beyond Homework Help
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
2
Replies
46
Views
7K
Back
Top