How to Use MatLab to Solve Matrix Equations and Perform Statistical Analysis
Part 1 of 2:
Solving the Matrix Equation
- Standardize your matrices to be usable in the standard form of a matrix equation, Ax = B.
- For this instruction set, the matrix equation [1 2 -2 ; 2 3 1 ; 3 2 -4] x = [9 ; 23 ; 11] will be used to illustrate the process of solving the equation.
- The matrix [1 2 -2 ; 2 3 1 ; 3 2 -4] is the coefficient matrix.
- The B matrix is [ 9 ; 23 ; 11].
- The variable x is the matrix of solutions to the equation.
- Create the A matrix.
- Open MATLAB.
- Click in the command window (the large window in the center of the screen) to prepare for typing text.
- Type the variable name, in this case 'A', and the equals sign ( = ).
- Insert a left bracket ( [ ) and type the given A matrix, starting from the top left and working to the right, separating each number by a comma or a space. Once the end of a row is reached, signify this by including a semicolon. Then type the first number of the next row and continue in the same way as above. Include the entire matrix in this way and then end the matrix with a right bracket ( ] ),
- Hit enter to store the variable in the MATLAB workspace.
- For the example matrix given in step 1, the user would type A = [ 1 2 -2 ; 2 3 1 ; 3 2 -4 ] and hit enter.
-
- Create the B matrix.
- Type the B matrix in the same format as explained above, or follow the shortened instructions below.
- Type the variable name followed by an equals sign. Then type a left bracket, the entries of the matrix, and a right bracket. Then hit enter.
- For the example, the user would type B = [ 9 ; 23 ; 11 ] and then hit enter.
-
- Check to see if the matrices are compatible for solving matrix equations. Do this by storing the size of each matrix as a variable and checking to see if there are the same number of columns in A as there rows in B.
- Visit http://math.sfsu.edu/smith/Documents/AppendixC.pdf to review why matrices must be tested for compatibility before being used in matrix algebra.
- Create a size variable for matrix A. Type a new variable name followed by an equals sign, then 'size', and the variable for the A matrix enclosed in parenthesis. Hit enter.
- For the example matrix, the user would type Asize = size(A) and hit enter.
- Create a size variable for matrix B in the same way as above.
- For the example, the user would type Bsize = size(B) and hit enter.
- Compare the rows of A to the columns of B by typing a new variable name followed by an equals sign. Then type a left parenthesis, the A size variable name and '(2)', two equal signs, your B size variable name, '(1)' and close the parenthesis. Hit enter.
- For the example matrix, the user would type comp = (Asize(2) == Bsize(1)) and hit enter.
- If the matrices are compatible, the output will be 1 and the matrices can be used for matrix equations.
- If the matrices are not compatible, the output will be 0 and the matrices cannot be used for matrix equations.
-
- Solve for x.
- Type 'x = ', the A matrix variable name, a backslash ( ), and the B matrix variable name. Hit enter.
- For the example, the user would type x = AB and hit enter.
- The solution will be stored in the variable x.
-
Part 2 of 2:
Performing Statistical Analysis
- Create the A matrix as a single row matrix.
- Type a new variable name for A, followed by an equals sign. Type a left bracket ( [ ) and each number in the matrix separated by a space or a comma. Close with a right bracket ( ] ) and hit enter.
- For the example matrix given in step 1 of part 1, the user would type Arow = [ 1 2 -2 2 3 1 3 2 -4] and hit enter.
-
- Calculate the number of data points by using the built-in function 'numel'.
- Type a new variable name, followed by an equals sign. Then type 'numel' and the name of the A matrix enclosed in parenthesis. Hit enter.
- For the example, the user would type Ntotal = numel(Arow) and hit enter.
-
- Calculate the minimum of the data by using the built-in function 'min'.
- Type a new variable name, followed by an equals sign. Then type 'min' and the name of your A matrix enclosed in parenthesis. Then hit enter.
- For the example, the user would type Amin = min(Arow) and hit enter.
-
- Calculate the maximum of the data by using the built-in function 'max'.
- Type a new variable name, followed by an equals sign. Then type 'max' and the name of the A matrix enclosed in parenthesis. Hit enter.
- For the example, the user would type Amax = max(Arow) and hit enter.
-
- Calculate the range of the data by subtracting the maximum value from the minimum value.
- Type a new variable name, followed by an equals sign. Then type the maximum variable name, the minus sign ( - ), and the minimum variable name. Hit enter.
- For the example, the user would type range = Amax - Amin and hit enter.
-
- Calculate the sum of the data by using the built-in function 'sum'.
- Type a new variable name, followed by an equals sign. Then type 'sum' and the name of the A matrix enclosed in parenthesis. Hit enter.
- For the example, the user would type Asum = sum(Arow) and hit enter.
-
- Calculate the mean (or average) of the data by using the built-in function 'mean'.
- Type a new variable name, followed by an equals sign. Then type 'mean' and the name of the A matrix enclosed in parenthesis. Hit enter.
- For the example, the user would type Amean = mean(Arow) and hit enter.
-
- Calculate the standard deviation (the square root of the variance) of the data by using the built-in function 'std'.
- Type a new variable name, followed by an equals sign. Then type 'std' and the name of the A matrix enclosed in parenthesis. Hit enter.
- For the example, the user would type Astd = std(Arow) and hit enter.
-
- Create a table to display the statistical analysis using the built-in function 'table'.
- Type a new variable name, followed by an equals sign. Then type 'table' and enclose each of the variables created for steps two through eight, separated by commas, enclosed in parenthesis. Hit enter.
- For the example, the user would type Stats = table(Ntotal, Amin, Amax, range, Asum, Amean, Astd) and hit enter.
-
4 ★ | 1 Vote
You should read it
- Matrix functions in Excel
- MINVERSE function - The function returns the inverse matrix of a given matrix in Excel
- The Matrix 4, in turn, announced a production suspension because of Covid-19, Keanu Reeves' Day in 2021 could be canceled.
- What is MATLAB?
- Eisenhower Matrix and To-Do List: Which Time Management Style Is Right For You?
- How to fix the problem of being unable to enter Terminal in Linux
- Silver batteries minimize the risk of explosion
- How to type fractions in Word
May be interested
- Three mathematical equations change the worldthe bbc news agency opened a poll for readers about the most significant mathematical equations. here are the 3 most voted equations, they are the development premise of many science branches today.
- Answer common questions about dot matrix printerswhat is a dot matrix printer, how much does it cost, how is it applied in life, how easy is it to use, which one is the best? read this article now to get answers to common questions about dot matrix printers!
- How to Import, Graph, and Label Excel Data in MATLABwhether you are an experienced matlab user or a novice, you may not be fully aware of matlab's graphing abilities. matlab allows you to easily customize, label, and analyze graphs, giving you more freedom than the traditional excel graph....
- Data Analysis in Exceldata analysis is excel's statistical tool, but it is not available in menu interface. in this article, dexterity software will guide you how to turn on the data analysis tool and use it.
- Matrix Ransomware is back under the distribution of RIG Exploit Kitsecurity researcher jérôme segura of malwarebytes has discovered matrix ransomware being distributed through rig exploit kit on malicious display sites.
- How to Enter Data in SPSSspss is a statistical analysis program that is used in a variety of fields, from market researchers to government agencies. it allows you to perform a variety of functions on your data, but you need data before you can do any of that....
- How to Download MATLAB on a Macdo you having trouble downloading matlab to your mac? matlab is a programming software that most undergraduate engineering students will download and use during their college career. this article will explain step-by-step how to download...
- How to Insert Equations in Microsoft Wordmodern versions of word have most of the symbols and equations that math experts need. you can enter these factors quickly using keyboard shortcuts or find them in the convenient equation menu, depending on your preference. the operation will be slightly different if you use a mac, or a word version from 2003 or lower. note, the 'insert object' method in word 2003 is not applicable to new versions. you can also write equations in word using the mobile app. this is an article showing how to insert equations in microsoft word in all cases.
- Matrix functions in Exceltoday i introduce to you 3 matrix functions commonly used in excel. the article will guide in detail the syntax and specific examples for each matrix function, hoping to help you a lot in your work.
- MINVERSE function - The function returns the inverse matrix of a given matrix in Excelcalculating the inverse matrix of a given matrix is very confusing and manual calculations take a lot of time. the following article shows how to use the minverse function in excel, which returns the inverse matrix of a given matrix.