You are on page 1of 7

Haider Yaseen MEEN201101082

Lab 01

Objective:
Introduction to MATLAB: its interface, dealing with variables, matrices & basic functions and
their applications. (Part-I)

Theory:
Introduction of MATLAB:
MATLAB is a powerful programming language and environment designed for numerical
computation, data analysis, and visualization. It is widely used in scientific research, engineering,
and mathematics to solve complex problems and develop innovative solutions.
MATLAB's name is derived from "Matrix Laboratory," as it was originally designed to handle
matrix computations. However, it has since grown to become a more comprehensive tool for data
analysis and visualization. It provides an interactive environment for programming, making it easy
for users to prototype and test algorithms, as well as create custom graphical user interfaces (GUIs)
for their applications.
MATLAB is based on a high-level programming language that allows users to perform complex
computations with just a few lines of code. It provides a wide range of built-in functions and
toolboxes for specialized applications such as signal processing, control systems, optimization,
and machine learning.
MATLAB's powerful visualization capabilities allow users to create custom plots, charts, and
graphs to represent their data in meaningful ways. It also supports the creation of 2D and 3D
animations and interactive visualizations.
Overall, MATLAB is a versatile tool that enables users to tackle a wide range of computational
and analytical challenges, making it an essential tool for many scientists, engineers, and
mathematicians.

1|Page
Haider Yaseen MEEN201101082

Figure 1 MATLAB Interfaces

MATLAB Desktop:
This is the main interface for working with MATLAB. It provides an interactive environment for
entering, executing, and debugging MATLAB code. The Desktop includes a Command Window,
which is used for entering commands and executing code, and a Workspace, which displays the
variables in memory.
MATLAB Editor:
This is a built-in code editor that provides a more efficient way to create, edit, and debug
MATLAB code. The Editor includes syntax highlighting, automatic code indentation, and
debugging tools.
Live Editor:
This is a newer interface introduced in MATLAB 2016b that combines the functionality of the
MATLAB Editor with the ability to create interactive documents that can include live code,
formatted text, equations, and visualizations.
Command Line Interface (CLI):
MATLAB can also be used through a command line interface, which allows users to execute
MATLAB commands and scripts from the terminal.
Simulink:

2|Page
Haider Yaseen MEEN201101082

Simulink is a block diagram environment for simulating and modeling dynamic systems. It
provides a graphical interface for designing and simulating complex systems, such as control
systems and signal processing algorithms.
MATLAB Apps:
MATLAB includes several built-in apps that provide interactive tools for specific tasks, such as
data analysis, image processing, and optimization.

MATLAB variables:
In MATLAB, variables are used to store data such as numbers, text, or arrays. They can be created
and manipulated in several ways:
Creating variables: To create a variable, simply assign a value to a name using the equals sign (=).
For example, to create a variable "x" with a value of 10, type "x = 10;".
Displaying variables: To display the value of a variable, simply type its name in the Command
Window. For example, to display the value of the variable "x", type "x" in the Command Window
and press Enter.
Modifying variables: Variables can be modified by assigning them a new value. For example, to
change the value of "x" to 20, type "x = 20;".
Clearing variables: To clear a variable from memory, use the "clear" command followed by the
variable name. For example, to clear the variable "x", type "clear x;".
Loading and saving variables: MATLAB provides functions to save and load variables from files.
The "save" function saves one or more variables to a file, while the "load" function loads variables
from a file.
Using built-in variables: MATLAB provides several built-in variables, such as "pi" for the value
of pi, "eps" for the machine epsilon, and "inf" and "NaN" for infinity and not-a-number,
respectively.

Matrices and Basic Functions and their applications


In MATLAB, matrices are a fundamental data type and can be created, modified, and operated on
using a variety of built-in functions and operators. Here are some common functions and their
applications:
Creating matrices: To create a matrix, use square brackets to enclose the elements of the matrix,
separated by commas or semicolons. For example, to create a 2x3 matrix "A" with values [1 2 3;
4 5 6], type "A = [1 2 3; 4 5 6];".

3|Page
Haider Yaseen MEEN201101082

Matrix arithmetic: MATLAB provides a variety of arithmetic operators for matrices, including
addition (+), subtraction (-), multiplication (*), and division (/). These operators can be used to
perform element-wise operations or matrix operations depending on the context.
Transpose: To transpose a matrix, use the apostrophe operator. For example, to transpose matrix
"A", type "A'".
Indexing: Elements of a matrix can be accessed using indexing. For example, to access the element
in row 2 and column 3 of matrix "A", type "A(2,3)".
Basic matrix functions: MATLAB provides several built-in functions for basic matrix operations,
such as "size" to determine the size of a matrix, "eye" to create an identity matrix, "zeros" to create
a matrix of zeros, and "ones" to create a matrix of ones.
Matrix functions: MATLAB provides a variety of built-in functions for advanced matrix
operations, such as "inv" to calculate the inverse of a matrix, "det" to calculate the determinant of
a matrix, "eig" to calculate the eigenvalues and eigenvectors of a matrix, and "svd" to calculate the
singular value decomposition of a matrix.
Statistical functions: MATLAB provides a variety of built-in functions for statistical analysis of
matrices, such as "mean" to calculate the mean of a matrix, "std" to calculate the standard deviation
of a matrix, "corrcoef" to calculate the correlation coefficient between two matrices, and
"histogram" to create a histogram of a matrix.
Overall, MATLAB provides a powerful set of functions for working with matrices and performing
numerical operations. These functions can be used for a variety of applications, including data
analysis, signal processing, and scientific computing.

Task 01:
Generate a vector A with elements ranging from 0 to 10 with spacing of 2.

Generate a 0 to 10 with 6 elements vector B with elements ranging [0,10]

4|Page
Haider Yaseen MEEN201101082

Task 02
Add A and B and assign resulting vector to X.

Square all the elements of vector X.

Task 03:
Find the solution to the following set of equations using the matrix inverse and left and right division.

r + s + t + w = 10

2r - s + w = 4

3r + s - t - w = -2

r - 2s - 3t + w = -8

5|Page
Haider Yaseen MEEN201101082

Task 04:
Find the solution to the following set of equations using the matrix inverse and left and right
division.

2x1 + x2 - 4x3 + 6x4 + 3x5 - 2x6 = 16

- x1 + 2x2 + 3x3 + 5x4 - 2x5 = -7

x1 - 2x2 - 5x3 + 3x4 + 2x5 + x6 = 1

6|Page
Haider Yaseen MEEN201101082

4x1 + 3x2 - 2x3 + 2x4 + x6 = -1

3x1 + x2 - x3 + 4x4 + 3x5 + 6x6 = -11

5x1 + 2x2 - 2x3 + 3x4 + x5 + x6 = 5

7|Page

You might also like