How to get an input matrix from user?

In summary, the conversation is about creating a program to implement matrix multiplication without using the MATLAB 'MULTIPLICATION COMMAND'. The program should prompt the user to enter the dimensions of the matrices, check if they are positive integers, and if multiplication is possible with those dimensions. Then, the user should enter the values of the matrices, the program should perform matrix multiplication, and display the resultant matrix. The user seems to be stuck and is seeking help.
  • #1
goofy
2
0
how to get an input matrix from user?

WITHOUT using the MATLAB ‘MULTIPLICATION COMMAND’ write down your own program to implement the matrix multiplication M = A*B, where A and B are two constant matrices of dimensions l x m and m x n, respectively. The program should:
 Prompt the user to enter the dimensions l, m and n;
 Check if all the dimensions are positive integers and if this is not the case, ask the user to enter the values again; also to check whether multiplication is possible or not according the entered dimensions
 Prompt the user to enter the values of the two matrices;
 Apply matrix multiplication M = A * B and calculate the product M;
 Display the resultant matrix M [don’t use ‘;’ at end of statement in order to display].

PLZ help i m get stuck...
 
Physics news on Phys.org
  • #2


What have you done so far?
 

FAQ: How to get an input matrix from user?

1. How do I prompt the user for input in a matrix format?

To prompt the user for input in a matrix format, you can use a combination of the input() function and a for loop. First, use the input() function to get the number of rows and columns from the user. Then, use a for loop to iterate through each row and column, asking the user for input and storing it in a list. Finally, use the list to create the input matrix.

2. What data type should I use for the input matrix?

The most common data type for a matrix is a list of lists. Each inner list represents a row in the matrix, and the outer list represents the entire matrix. However, you can also use other data types such as NumPy arrays or Pandas dataframes depending on your specific needs.

3. How can I validate the user's input in the matrix?

To validate the user's input in the matrix, you can use conditional statements and try-except blocks. For example, you can check if the user entered the correct number of rows and columns, or if the input values are of the expected data type. Additionally, you can use a loop to continuously prompt the user for input until it is valid.

4. Can I create a matrix with predefined values and still prompt the user for additional input?

Yes, you can create a matrix with predefined values and still prompt the user for additional input. You can do this by first creating the matrix with the predefined values, and then using a for loop to prompt the user for input and replace the corresponding values in the matrix. Alternatively, you can use the extend() function to add the user's input values to the end of the predefined matrix.

5. How can I display the input matrix to the user?

To display the input matrix to the user, you can use a for loop to iterate through each row and column and print it out in a visually appealing format. You can also use built-in functions such as print() or join() to customize the appearance of the matrix. Additionally, you can use libraries such as NumPy or Pandas to create more advanced visualizations of the matrix.

Similar threads

Replies
2
Views
1K
Replies
17
Views
5K
Replies
1
Views
2K
Replies
10
Views
2K
Replies
4
Views
2K
Back
Top