0% found this document useful (0 votes)
11 views4 pages

Sheet 3

The document provides an overview of mathematical operations using MATLAB, including column-oriented, array arithmetic, and matrix operations. It explains how to perform various arithmetic operations on arrays and matrices, as well as methods for solving systems of linear equations using matrix notation. Additionally, it includes examples of MATLAB commands for executing these operations and solving equations efficiently.

Uploaded by

rasha waleed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Sheet 3

The document provides an overview of mathematical operations using MATLAB, including column-oriented, array arithmetic, and matrix operations. It explains how to perform various arithmetic operations on arrays and matrices, as well as methods for solving systems of linear equations using matrix notation. Additionally, it includes examples of MATLAB commands for executing these operations and solving equations efficiently.

Uploaded by

rasha waleed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Engineering Analysis Laboratory

Experiment [3]
Mathematical Operations using MATLAB

Introduction:
MATLAB has three different types of arithmetic operations: column oriented
operations, array oriented operations and matrix arithmetic operations.
1) Column Oriented Operation
This type of operation deal with each colunm, for example
Sum(a), max(a), min(a)
2) Array Arithmetic Operation
Array arithmetic operations are carried out element by element, and can be used with
multidimensional arrays. Arithmetic operations are (addition, subtraction, multiplication,
division and power).
Addition (A+B): Adds A and B. Both of A and B must have the same size, unless one of
them is a scalar. A scalar can be added to a matrix of any size.
Subtraction (A-B): Subtracts B from A. Both of A and B must have the same size, unless
one is a scalar. A scalar can be subtracted from a matrix of any size.
.* Array multiplication (A.*B): is element by element product of the arrays A and B. A
and B must have the same size, unless one of them is a scalar.
./ Array right division (A./B): is the matrix with elements A(i,j)/B(i,j). A and B must have
the same size. Unless one of them is a scalar.
.\ Array left division (A.\B): is the matrix with elements A(i,j)\B(i,j). A and B must have
the same size. Unless one of them is a scalar.
.^ Array power (A.^B): is the matrix with elements A(ij) to the B(ij) power. A and B
must have the same size. Unless one of them is a scalar.
.' Array transpose (A.' ): is the array transpose of A. For complex matrices, this does not
involve conjugation.

1
Engineering Analysis Laboratory

3) Matrix operations
Matrix arithmetic operations are defined by the rules of linear algebra, the matrix and
array operations are same for addition and subtraction.
Matrix multiplication (A*B): is the linear algebraic product of the matrices A and B.
More precisely

( ) ∑ ( ) ( )

For nonscalar A and B, the number of columns of A must equal the number of rows of
B. A scalar can multiply a matrix of any size.
Slash or matrix right division(A/B): is roughly the same as: B*inv(A). more precisely:
B/A=(A'/B')'
Backslash or matrix right division(A/B): If A is a square matrix B\A is roughly the same
as: inv(B)*A. more precisely: B/A=(A'/B')'
^ Matrix power(X^p): is X to the power p, if p is a scalar. If p is an integer, the power is
computed by repeated squaring. If the integer is negative, X is inverted first.
Matrix operations vs. array operations
Here are two vectors, and the results of various matrix and array operations on them.

2
Engineering Analysis Laboratory

Solving linear equations:


One of the problems encountered most frequently in scientific computation is the
solution of systems of simultaneous linear equations. With matrix notation, a system of
simultaneous linear equations is written: Ax = b
where there are as many equations as unknowns. A is a given square matrix of order n, b
is a given column vector of n components, and x is an unknown column vector of n
components.
In linear algebra we learn that the solution to Ax=b can be written as x=A-1 b where A-1
is the inverse of A. For example, consider the following system of linear equations:
x+2y+3z=1
4x+5y+6z=1
7x+8y =1
Using matrix notation, a system of simultaneous linear equations is written as: Ax=B ,
where:

[ ] , [ ]

This equation can be solved for x using linear algebra. There are two ways to solve for
x using MATLAB:
1. The first way is to use the matrix inverse:
>> A=[ 1 2 3; 4 5 6; 7 8 0];

3
Engineering Analysis Laboratory

> >B=[ 1 ; 1 ; 1];


>> x=inv(A) *B
x=
-1
1
0
2. The second way is to use the backslash operation. The numerical algorithm behind
this operator is computationally efficient. This is numerically reliable way of solving
a system of linear equations by using a well-known process of Gaussian elimination:
>> A =[1 2 3; 4 5 6; 7 8 0];
>>B = [1; 1; 1];
>>x=A\B
x=
-1
1
0

Experiment:
1- What are the results of the following instructions:
>> a=[5 2 3 5 8];
>> b=[9 2 5 0 8];
>> a'
>>a-1
>>a.*b
>> a*b
>>a.^3

2-What is the result of each the following command?


>>B=magic(4)
>>A=B(: , [1 3 2 4])
Delete the 3rd row

3-Find the matrix a - bc2 + 2d' when the matrices a, b, c and d are:

[ ] [ ]

[ ] [ ]

You might also like