Please I need help with a program for my exam
|
11-15-2024, 12:52 PM
Post: #1
|
|||
|
|||
Please I need help with a program for my exam
I want to create a program for HP Prime that calculates the savings matrix giving a matrix A and a matrix B.
How does it do it? well I give the calculator a square matrix n x n called A and a horizontal matrix n called B. What it does is for every cell in the savings matrix it puts the corresponding value: in the first cell 11 it would put: value 1 of B + value 1 of B - value 11 of A. in the cell 12 it would put: value 1 of B + value 2 of B - value 12 of A. In the cell 54 it would put: value 5 of B + value 4 of B - value 54 of A. The problem is that the program doesn't work, it says that there is an input error and I cannot even write the matrixes A and B. It just doesn't run. What I wrote is: EXPORT SavingsMatrix() BEGIN // Input the square matrix A LOCAL A, B, S, n, i, j; // Prompt the user for inputs A := INPUT({{}},"Enter matrix A: "); B := INPUT({{}}, "Enter vector B: "); // Validate dimensions n := SIZE(B); // Size of B must match rows/cols of A IF SIZE(A)≠n OR SIZE(A(1))≠n THEN PRINT("Error: A must be square, and B must match A size."); RETURN; END; // Create the savings matrix S S := MAKEMAT(0, n, n); // Initialize nxn matrix S // Calculate each element of the savings matrix FOR i FROM 1 TO n DO FOR j FROM 1 TO n DO S(i,j) := B(i) + B(j) - A(i,j); END; END; // Output the result PRINT("Savings Matrix S:"); RETURN S; END; |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Please I need help with a program for my exam - David0306 - 11-15-2024 12:52 PM
RE: Please I need help with a program for my exam - komame - 11-16-2024, 04:33 PM
RE: Please I need help with a program for my exam - David0306 - 11-18-2024, 01:51 PM
|
User(s) browsing this thread: 3 Guest(s)