Introduction To Matlabm
Introduction To Matlabm
Introduction To Matlabm
MATLAB is created by the MathWorks in 1984, is a computer program that provides the user with a
convenient environment in performing many types of calculations. It is a program for doing numerical
computations. It was originally designed for solving linear algebra type problems using matrices. Its
name matlab is derived from matrix laboratory.
Student will be able to familiarize and use matlab commands in solving of root of equation/s.
The most common way to operate matlab is by entering commands one at a time in the command
window. Some basic editing commands in the main matlab are as follows:
Matlab required a personal computer or laptop to install the program. Fortunately, matlab can be
download in your smart phone by play store. Using matlab on smart phone must have data or wifi
connection because its not offline application. The computation on pc it almost same as our smart
phone. On play store just search "Matlab Mobile".
Evaluate x2 + xy + y2, if x = 2, y = 3
>> x = 2; y = 3;
>> x^2+x*y+y^2
ans =
19
write the polynomial expression by numerical coefficient [1 -7 10]. On command window encode
>>t = [1 -7 10]
>>roots(t)
ans =
Notice on the expression that their is a missing x 2 and x terms, then replace it by "0"
answer is -1.000 + 0.000i only because the other two are imaginary number, therefore x = -1
Solve 2x + 3y = 11
3x - 4y = -9
Solve x – y – 2z = –1
2x + 3y + z = –2
5x + 4y + 2z = 4
change the system of linear equations to augmented matrix name it matrix B and encode to your
Matlab mobile just like below
Solve x – y – 2z = –1
2x + 3y + z = –2
5x + 4y + 2z = 4
change the system of linear equations to augmented matrix name it matrix B and encode to your
Matlab mobile just like below
https://youtu.be/lY-9vyFtb44
The availability of technical computing environment such as MATLAB is now reshaping the role and
applications of computer laboratory projects to involve students in more intense problem-solving
experience. This availability also provides an opportunity to easily conduct numerical experiments and
to tackle realistic and more complicated problems.
2 To determine the sum of row, column and diagonal of a matrix using MATLAB.
3 To create a matrix that has same sum of row, column and diagonal of different dimensions using
MATLAB
Students will be able to encode matrices on matlab and create magic square.
A=
[0 7 23 19 11;18 14 1 5 22; 6 20 17 13 4; 12 3 9 21 15; 24 16 10
2 8]
2. Determine the sum of rows, columns and diagonal of matrix B using matlab.
Type on command window
>>B = (10*rand(10, 10))
3. Determine the sum of row, column and diagonal of matrix C using matlab.
Type on command window
>>C = magic (10)
4. Make a magic square of different dimensions without using negative numbers, without repeating
numbers, avoid copying and adding/subtracting numbers on the default magic square of MATLAB.
An n-by-n magic square is an array containing the integers from 1 to n 2, arranged so that each of the
rows, each of the columns, and the two principal diagonals have the same sum. For each n > 2, there are
many different magic squares of order n, but the MATLAB function magic(n) generates a particular one.
Write the sum of rows, columns and diagonal in the blank.
1. Identify a linear equation and system of linear equation classification based on its solution set.
3. Apply Gaussian Elimination and Gauss-Jordan Elimination in solving systems of linear equations.
4. Reflect on how systems of linear equation can help solve simple real life situations.
5. Investigate the difference between Gaussian elimination and Gauss Jordan Elimination method.
7. Create a practical/ real life solution that will require the use of the system of linear equations.
TOPICS :
1. Linear Equation
In this module we will be learning about linear equation and system of linear equation, its solution
set and the method of elimination.
One example is a business organization. This system’s inputs are its capital, employees, raw
materials and factories. Its outputs are its products. Management decides what the interactions among
the inputs should be to give the maximum output (for example, how many factories should make which
products, etc.)
A linear system is a system where the output is proportional to the input. For example, if the
business organization is a linear system, then if we double the capital, employees, raw materials and
factories (the inputs) then we expect to get double the production (the output).
We can describe mathematically how the parts of a linear system relate to one another and to
the input using a system of linear equations. If a linear system has n parts (where n is some number),
then we can describe it with a system of n linear equations in n unknowns or variables. The unknowns in
these equations are the values of the inputs. If we did the analysis correctly then there will be a unique
solution for the values of the inputs.
This module also introduced Gaussian elimination as a procedure for solving a system of linear
equations. In this module, you will study this procedure more thoroughly, beginning with some
definitions
Rewriting a system of linear equations in row-echelon form usually involves a chain of equivalent
systems, each of which is obtained by using one of the three basic operations. This process is called
Gaussian elimination, after the German mathematician Carl Friedrich Gauss (1777–1855).
https://mathonweb.com/help_ebook/html/systems_0.htm
1.3 Gaussian and Gauss -Jordan Elimination
Hi, did you know that Carl Friedrich Gauss championed the use of row reduction, to the extent that it
is commonly called Gaussian elimination. It was further popularized by Wilhelm Jordan, who attached
his name to the process by which row reduction is used to compute matrix inverses, Gauss-Jordan
elimination.
In Gaussian elimination, you apply elementary row operations to a matrix to obtain a (row-equivalent)
row-echelon form. In Gauss-Jordan elimination continues the reduction process until a reduced row-
echelon form is obtained.
Let us define some important terms in solving the system of linear equation using Gaussian
Elimination and Gauss-Jordan Elimination
Matrix
Row- Echelon Form (REF)- A matrix in row-echelon form has the following properties.
a. All rows consisting entirely of zeros occur at the bottom of the matrix.
b. For each row that does not consist entirely of zeros, the first nonzero entry is 1 (called a leading
1).
c. For two successive (nonzero) rows, the leading 1 in the higher row is farther to the left than the
leading 1 in the lower row.
Take note : A matrix in row-echelon form is in reduced row-echelon form (RREF) if every column that
has a leading 1 has zeros in every position above and below its leading 1.
2. Use elementary row operations to rewrite the augmented matrix in row-echelon form.
3. Write the system of linear equations corresponding to the matrix in row-echelon form, and use
back-substitution to find the solution.
R E M A R K: In Gauss- Jordan elimination continue the process of reduction until a reduced row-echelon
form is obtained.
1.4 Watch & Learn System of Linear Equation
After watching this video click " Practice Exercise 1.1 " for your Exercises on the System of Linear
Equation. Click " Practice Exercise 1.2 " for your Exercises on Gaussian and Gauss- Jordan Elimination.
Questions and clarification can be asked by clicking " Ask and Learn ".
https://youtu.be/vA-55wZtLeE
https://youtu.be/lP1DGtZ8Wys
Fundamentals of MATLAB
• Is a versatile piece of computer software with linear algebra capabilities as its core
• The code employed by MATLAB is written in C Language, however, many of the routines and
functions are written in the MATLAB language and are upgraded as new versions of MATLAB are
released.
–matrix manipulation,
–implementation of algorithms,
• MATLAB is available for Windows, Macintosh and UNIX systems. It is used by more than one
million people in industry and academia.
• Rich data types: Complex number, Three dimensional matrix, structure, cell array, etc
• Lots of nice functions and toolboxes: fminsearch, fsolve, normcdf, norminv, etc; garch,
optimization, symbolic, …
MATLAB WINDOWS
• Command Window
The command window is located in the center pane of the default view of the MATLAB ® screen, as
shown in Figure 1 . The command window offers an environment similar to a scratch pad. Using it allows
you to save the values you calculate, but not the commands used to generate those values. If you want
to save the command sequence, you will need to use the editing window to create an M-file .
• Command History
The command history window records the commands you issued in the command window. When you
exit MATLAB ® , or when you issue the clc command, the command window is cleared. However, the
command history window retains a list of all your commands. You may clear the command history with
the edit menu. If you work on a public computer, as a security precaution, MATLAB ® ’s defaults may be
set to clear the history when you exit MATLAB ®
• Workspace Window
The workspace window keeps track of the variables you have defined as you execute commands in
the command window. These variables represent values stored in the computer memory, which are
available for you to use.
The current folder window lists all the files in the active directory. When MATLAB ® either accesses files
or saves information, it uses the current folder unless told differently. The default for the location of the
current folder varies with your version of the software and the way it was installed
–The command window environment is a powerful tool for solving engineering problems
• Using Variables
Giving names to the values you are using. MATLAB uses the naming conventions that are common to
most computer programs.
• Scalar Operations
MATLAB ® handles arithmetic operations between two scalars much as do other computer programs
and even your calculator.
x=
8
Order of Operations
In all mathematical calculations, it is important to understand the order in which operations are
performed. MATLAB ® follows the standard algebraic rules for the order of operation.
Note: Be sure to create account for Mathworks and install MATLAB software or the MATLAB mobile
app so you may be able to do the MATLAB Activity
After reading and understanding this page click "Mark as Done". However if you have questions and
clarification click " Ask and Learn ".
1.6 Summary
A linear equation is an equation involving one or more variables in which only the operations of
multiplication by real numbers and summing of terms are allowed. When several linear equations
involving the same variables are considered together, a system of linear equations is obtained. Many
methods are available for finding the complete solution set for a given linear system.
Gaussian elimination with back-substitution works well for solving systems of linear equations by
hand or with a computer. For this algorithm, the order in which you perform the elementary row
operations is important. Operate from left to right by columns, using elementary row operations to
obtain zeros in all entries directly below the leading 1’s.
With Gaussian elimination, you apply elementary row operations to a matrix to obtain a (row-
equivalent) row-echelon form. A second method of elimination, called Gauss-Jordan elimination, after
Carl Friedrich Gauss and Wilhelm Jordan (1842–1899), continues the reduction process until a reduced
row-echelon form is obtained.
2. 0 Intended Learning Outcomes
(ILOs)
1. A+B =B+A
2. A+(B+C)=(A+B)+C
3. There is a unique m x n matrix O (zero matrix) such that A + O =A for any mxn matrix
A.
4. For each mxn matrix A, there is a unique mxn matrix D such that A+ D= O. Where
matrix D is –A (negative of A)
Scalar multiplication
The scalar multiplication cA of a matrix A and a number c (also called a scalar in the
parlance of abstract algebra) is given by multiplying every entry of A by c: (cA)i,j = c · Ai,j.
Properties:
If r and s are real numbers and A and B are matrices of the appropriate size then:
1. r(sA)=(rs)A
2. (r+s)A=rA+sA
3. r(A+B)=rA+rB
4. A(rB)=r(AB)=(rA)B
Matrix multiplication
Multiplication of two matrices is defined only if the number of columns of the left matrix
is the same as the number of rows of the right matrix. If A is an m-by-n matrix and B is
an n-by-p matrix, then their matrix product AB is the m-by-p matrix whose entries are
given by dot-product of the corresponding row of A and the corresponding column of B:
R E M A R K S:
Properties
If A and B are matrices (with sizes such that the given matrix products are defined)
and c is a scalar, then the following properties are true.
1. A(BC)=(AB)C
2. A(B+C)=AB+AC
3. (A+B)C=AC+BC
4. c(AB)=(cA)B=A(cB)
https://youtu.be/WR9qCSXJlyY
https://youtu.be/TbaltFbJ3wE
https://youtu.be/kT4Mp9EdVqs
https://youtu.be/r9aTLTN16V4
A= [4 5 8;0 -1 6];
assigns the same matrix to name A as previously but no display appears. To assign a
currently defined matrix a new name, use the assignment operator = . Command Z = A
assigns the contents of A to Z. Matrix A is still defined
4. To determine the matrix names that are in use , use the who command.
5 To delete a matrix, use the clear command, followed by a space and then the matrix
name.
6. To determine the number of rows and columns in a matrix, use the size
command.
NOTE:
• If the matrix is quite large, the screen display will scroll too fast for you to see
the matrix.
• To see a portion of a matrix, type command more on followed by ENTER.
then type the matrix name or a command to generate it. Press the Space Bar
to reveal more of the matrix. Continue pressing the Space Bar until the "--
more--" no longer appears near the bottom of the screen
• To see the (2, 3) entry of A, type A(2,3)
• To see the fourth row of A, type A(4,:)
• To see the first column of A, type A (:, 1)
• In the preceding situations. the: is interpreted to mean "all." The colon can also
be used to represent a range of rows or columns. For example. Typing 2:8
displays
ans=
2 3 4 5 6 7 8
Display Formats
MATLAB stores matrices in decimal form and does its arithmetic computations using a
decimal-type arithmetic. This decimal form retains about 16 digits, but not all digits must
be shown.
• If the matrix contains all integers, then the entire matrix is displayed as
integer values; that is, no decimal points appear
• If any entry in the matrix is not exactly represented as an integer, then the
entire matrix is displayed in what is known a. format short. Such a display
shows four places behind the decimal point, and the last place may have been
rounded. The exception to this is zero. If an entry is exactly zero, then it is
displayed as an integer zero. Enter the matrix
Matrix Operations
• + addition
• - subtraction
• * multiplication
• ^ power
• ‘ transpose for a real matrix and complex –conjugate transpose for a complex
matrix (transpose for a complex matrix is .’)
• \ left division, / division
x = A \ b is the solution of A * x = b
Matrix multiplication
–Dimensions must agree
Transpose of Matrix
• In MATLAB the transpose operator (or symbol) is the single quotation mark, or
prime, '. Using the matrices in Example I find C’ and A’
•
• The following are the function syntax that can be used to manipulate
matrices:
• Matrix Manipulation
sum -calculate the sum of the entry in the column of the matrix
2.6 Summary
• When performing addition, add each element in the first matrix to the corresponding
element in the second matrix.
• When performing subtraction, subtract each element in the second matrix from the
corresponding element in the first matrix.
• Addition and subtraction require that the matrices be the same dimensions. The
resultant matrix is also of the same dimension.
• Scalar multiplication of a real Euclidean vector by a positive real number multiplies
the magnitude of the vector without changing its direction.
• If A is an n×m matrix and B is an m×p matrix, the result AB of their multiplication
is an n×p matrix defined only if the number of columns m in A is equal to the
number of rows m in B.
• The product of a square matrix multiplied by a column matrix arises naturally in linear
algebra for solving linear equations and representing linear transformations.
A square matrix that has an inverse is called invertible or non-singular. A matrix that
does not have an inverse is called singular.
A matrix does not have to have an inverse, but if it does, the inverse is unique.