0% found this document useful (0 votes)
36 views

Co Lab 01

The lab report introduces MATLAB, covering its interface, variables, matrices, basic functions, and applications. The interface includes command, workspace, editor, and figure windows. Variables are defined using assignment operator "=" and can be numeric, character, or logical types. Matrices use square brackets and separate elements by spaces/commas. Basic functions include trigonometric, exponential, logarithmic, and plotting functions. Tasks generate vectors, add and square elements, and solve systems of equations using matrix inverse and left/right division.

Uploaded by

・ A卄SAN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Co Lab 01

The lab report introduces MATLAB, covering its interface, variables, matrices, basic functions, and applications. The interface includes command, workspace, editor, and figure windows. Variables are defined using assignment operator "=" and can be numeric, character, or logical types. Matrices use square brackets and separate elements by spaces/commas. Basic functions include trigonometric, exponential, logarithmic, and plotting functions. Tasks generate vectors, add and square elements, and solve systems of equations using matrix inverse and left/right division.

Uploaded by

・ A卄SAN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

lOMoAR cPSD| 24965850

lOMoAR cPSD| 24965850

CONTROL ENGINEERING LAB


Lab Report 01

Instructor Engr. Adnan Rasheed


Submitted By MEEN201101055
Semester 6th

Khawaja Fareed University of Engineering &


Information Technology,
Rahim Yar Khan

Downloaded by ? A?SAN
lOMoAR cPSD| 24965850

Lab Report 01

Objective:
Introduction to MATLAB: its interface, dealing with variables, matrices & basic functions & their
applications.

Theory:

Introduction to MATLAB:
MATLAB is a high-level programming language and interactive environment widely used for
scientific computing and data analysis. Its name stands for "matrix laboratory," which reflects its
primary focus on matrix computations. In this introduction to MATLAB, we will cover its interface,
how to deal with variables, matrices, and basic functions, as well as their applications.

MATLAB Interface:
The MATLAB interface consists of several windows, including the Command Window, the
Workspace Browser, the Editor, and the Figure Window. The Command Window is where you can
enter MATLAB commands and see the results of those commands. The Workspace Browser displays
the variables currently in the workspace, and the Editor allows you to write and edit MATLAB code.
The Figure Window is where MATLAB plots and other graphical output are displayed.

Fig 01: MATLAB interface

Downloaded by ? A?SAN
lOMoAR cPSD| 24965850

Defining Variables:
In MATLAB, variables are used to store data. Variables can be defined using the assignment
operator "=" and can be any valid name that starts with a letter and consists of letters, numbers, and
underscores. For example:
x = 10
y = 2.5
name = 'John'

Fig 02 : Dealing with variables


MATLAB has several built-in data types, including numerical types (integers, floating-point
numbers), character arrays, and logical values (true or false). You can use the "whos" command in
the Command Window to see the variables in the workspace and their data types.

Matrices:
MATLAB is designed to work with matrices. Matrices are defined using square brackets "[ ]" and
elements are separated by spaces or commas. Rows are separated by semicolons ";" and columns are
separated by spaces or commas. For example:

A = [1 2 3; 4 5 6; 7 8 9]
B = [1, 2, 3; 4, 5, 6; 7, 8, 9]

Fig 03: Matrices

Downloaded by ? A?SAN
lOMoAR cPSD| 24965850

MATLAB has several built-in functions for creating matrices, such as zeros, ones, and eye. You can
also use indexing to access individual elements of a matrix, rows, or columns. For example:
A (2,3) % returns the element in the second row, third column of matrix A
A (:2) % returns the second column of matrix A

Basic Functions and Applications:


MATLAB has a large number of built-in functions for performing a wide range of mathematical
operations. Some common functions include:
sqrt: computes the square root of a number
sin, cos, tan: computes the trigonometric functions of an angle
sum: computes the sum of all the elements in a matrix
mean: computes the mean of all the elements in a matrix
max, min: finds the maximum or minimum value in a matrix
plot: creates a 2D line plot of data
sin(x) % returns the sine of x (in radians)
cos(x) % returns the cosine of x (in radians)
exp(x) % returns the exponential of x
log(x) % returns the natural logarithm of x
sqrt(x) % returns the square root of x

MATLAB also has many functions for creating and manipulating plots, such as plot, scatter, and
histogram. For example:
x = Linspace(0,2*pi,100);
y = sin(x);
plot (x, y)
This code creates a plot of the sine function over the range [0, 2π] with 100 points. The "linspace"
function is used to create an evenly spaced vector of 100 points between 0 and 2π.

Downloaded by ? A?SAN
lOMoAR cPSD| 24965850

Task 01

Generate a vector A with elements ranging from 0 to 15 with spacing of 3. Generate a 0 to 15 with 6
elements vector B with elements ranging [0,15].
MATLAB code:
A=[0:3:15]
B=linspace(0,15,6)

Performed Task screenshot:

Fig 04: Task 01

Downloaded by ? A?SAN
lOMoAR cPSD| 24965850

Task 02

Add A and B and assign resulting vector to X. Square all the elements of vector X.
MATLAB code:
X= A+B Y=X.^2

Performed Task screenshot:

Fig 05: Task 02

Downloaded by ? A?SAN
lOMoAR cPSD| 24965850

Task 03

Find the solution to the following set of equations using the matrix inverse and left and right
division.
í + s + t + w = 10 2í - s + w = 4
3í + s - t - w = -2
í - 2s - 3t + w = -8
MATLAB code:
C= [1 1 1 1
2 -1 0 1
3 1 -1 -1
1 -2 -3 1] D=[10;4;-2;-8]
% matrix inverse V_1=inv(C)*D
% Or by left and right division. V_2=C\D

Performed Task screenshot:

Fig 06: Task 03

Downloaded by ? A?SAN
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 = 6
- x1 + 2x2 + 3x3 + 5x4 - 2x5 = 7 x1 - 2x2 - 5x3 + 3x4 + 2x5 + x6 = 0 4x1 + 3x2 - 2x3 + 2x4 + x6 = 8
3x1 + x2 - x3 + 4x4 + 3x5 + 6x6 = 16
MATLAB code:
E=[2 1 -4 6 3 -2
-1 2 3 5 -2 0
1 -2 -5 3 2 1
4 3 -2 2 0 1
3 1 -1 4 3 6
5 2 -2 3 1 1] F=[6;7;0;8;16;0]
% matrix inverse W_1=inv(E)*F
% Or by left and right division. W_2=E\F

Performed Task screenshot:

Fig 07: Task 04

You might also like