How to Define, Add, and Subtract Matrices in MATLAB
Launch MATLAB and wait until you get a screen similar to the one shown., Type a letter, word, or otherwise simple identifier for your new matrix in the command window., Type an "=" followed by a left bracket, "["., Begin adding values to your...
Step-by-Step Guide
-
Step 1: Launch MATLAB and wait until you get a screen similar to the one shown.
Depending on your edition, you may get a message stating "Student License
--".
This is not an error and should not hinder functionality. -
Step 2: Type a letter
Note that the identifier may not contain spaces and that all identifiers are case sensitive.
Therefore, "A" is not the same as "a".
In this example, we will define our matrix as "A". , Typing, "A=[" is the same as, "A = [".
Spacing in between these characters is acceptable. , These values may be numbers or other predefined variables.
In this case, we will stick to just whole numbers.
Columns in a matrix are separated with spaces, i.e. pressing the "Space Bar" after typing a number or variable.
Rows are separated with semicolons.
Close the matrix with a right bracket, "]". , The matrix you have just defined will print itself in the "Command Window".
It will also be visible in the "Workspace" window. , If you are content with the way your matrix is defined, you may now perform functions with it.
If your matrix does not appear as desired, you may easily re-define it.
Perform the exact same steps as above.
As long as you choose the exact same identifier, the old matrix will be updated with the new data.
Note the change in the "Workspace" window. , In this example, we will use two matrices.
These have identifiers "A" and "B". , If they are not, you will get an error message., Type the identifier of the second matrix to be added.
Continue this process for all desired matrices, being sure to separate the identifiers with plus signs. ,, You should see the desired result printed to the screen, and the new variable "ans" in the "Workspace" window., You may now take matrix "ans" and perform many more calculations with it.
Treat "ans" the same way you would any other matrix identifier.
All of the same addition and subtraction rules apply. -
Step 3: or otherwise simple identifier for your new matrix in the command window.
-
Step 4: Type an "=" followed by a left bracket
-
Step 5: Begin adding values to your matrix.
-
Step 6: Click ↵ Enter to officially define your matrix.
-
Step 7: Review your work.
-
Step 8: Define the desired matrices
-
Step 9: as explained above.
-
Step 10: Realize that
-
Step 11: in order to be added or subtracted
-
Step 12: two matrices need to be the same length and width.
-
Step 13: Type the identifier of the first matrix followed by a plus sign
-
Step 14: if you want to do addition
-
Step 15: or a "-" sign if you want to do subtraction.
-
Step 16: Press ↵ Enter.
-
Step 17: Check the answer.
-
Step 18: Perform more calculations.
Detailed Guide
Depending on your edition, you may get a message stating "Student License
--".
This is not an error and should not hinder functionality.
Note that the identifier may not contain spaces and that all identifiers are case sensitive.
Therefore, "A" is not the same as "a".
In this example, we will define our matrix as "A". , Typing, "A=[" is the same as, "A = [".
Spacing in between these characters is acceptable. , These values may be numbers or other predefined variables.
In this case, we will stick to just whole numbers.
Columns in a matrix are separated with spaces, i.e. pressing the "Space Bar" after typing a number or variable.
Rows are separated with semicolons.
Close the matrix with a right bracket, "]". , The matrix you have just defined will print itself in the "Command Window".
It will also be visible in the "Workspace" window. , If you are content with the way your matrix is defined, you may now perform functions with it.
If your matrix does not appear as desired, you may easily re-define it.
Perform the exact same steps as above.
As long as you choose the exact same identifier, the old matrix will be updated with the new data.
Note the change in the "Workspace" window. , In this example, we will use two matrices.
These have identifiers "A" and "B". , If they are not, you will get an error message., Type the identifier of the second matrix to be added.
Continue this process for all desired matrices, being sure to separate the identifiers with plus signs. ,, You should see the desired result printed to the screen, and the new variable "ans" in the "Workspace" window., You may now take matrix "ans" and perform many more calculations with it.
Treat "ans" the same way you would any other matrix identifier.
All of the same addition and subtraction rules apply.
About the Author
Andrea Jordan
Creates helpful guides on practical skills to inspire and educate readers.
Rate This Guide
How helpful was this guide? Click to rate: