0% found this document useful (0 votes)
8 views3 pages

Introduction to MATLAB Basics

This document is an introductory lab experiment for MATLAB at MNS University of Engineering & Technology, covering basic concepts and functionalities of the software. It includes objectives, instructions for entering and quitting MATLAB, matrix and vector manipulation, built-in functions, and graphing techniques. The document also contains several exercises for practical application of the concepts discussed.

Uploaded by

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

Introduction to MATLAB Basics

This document is an introductory lab experiment for MATLAB at MNS University of Engineering & Technology, covering basic concepts and functionalities of the software. It includes objectives, instructions for entering and quitting MATLAB, matrix and vector manipulation, built-in functions, and graphing techniques. The document also contains several exercises for practical application of the concepts discussed.

Uploaded by

moazzamarain444
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

MNS UNIVERSITY OF ENGINEERING & TECHNOLOGY,

MATLAB INTRO
Lab Experiment #1

Name: _______________________________________________________ Roll No: _________________

Score: _______________ Signature of the Lab Tutor: _______________________ Date: ______________


______________________________________________________________________________________

Lab 1
An Introduction to MATLAB

1. What is MATLAB:dicussion.

The name MATLAB is short for MATrix LABoratory. It is a commercial software package
whose main function is to perform calculations on matrices, row vectors and column vectors.
It is widely used in both industry and academic institutions. It possesses many of the features
of a high level, numerically oriented programming language, but in addition has a large
collection of built-in functions for performing matrix and vector operations in a way that is
very simple for the user. For example, to find the determinant of a matrix A one need only
enter:
det(A)
MATLAB commands can be entered one line at a time, or the user can write programs of
MATLAB code and define his or her own functions. In this session, we shall only use the
one-line-at-a-time “interpretive” mode for simplicity, but the regular user will find that the
power of the package is considerably extended by writing his or her own programs and
functions.

2. Objectives

The objectives of these notes are to give a brief general introduction to MATLAB and to
familiarize you with the most commonly used functions of MATLAB.
The notes contain exercises that you should try out as you go along and are intended to be
reasonably self-contained. However, the MATLAB manuals contain tutorial introductions
and there are built-in demonstrations and tutorial material in the MATLAB software itself. At
present MATLAB version 6.1 is available. However, on our computers, MATLAB version
5.3 has been installed.

3. Entering and quitting MATLAB

To enter MATLAB, simply double click on the MATLAB icon. To leave MATLAB and
return to the PC’s operating system
simply type
quit

4. Creating and manipulating matrices and vectors

MATLAB works on matrices and vectors that may be real or complex. Variables do not have
to be “declared”. Results can be displayed in a variety of different formats.
Let us enter a row vector into the MATLAB workspace. Type in:

1
MNS UNIVERSITY OF ENGINEERING & TECHNOLOGY,
MATLAB INTRO
Lab Experiment #1
v = [2 4 7 5]
This creates a variable v whose current value is a row vector with four elements as shown.
After pressing “return” the value of v will have been echoed back to you. To suppress the
echo, one uses a semi-colon following the command line. Thus
w = [1 3 8 9];
Creates another row vector w, but does not echo. To check that w has appeared in the
MATLAB workspace, type,
who
Which will display all the variables in the MATLAB workspace, and to check the value of w
simply type w
Operations on row vectors can be best illustrated by some simple exercises.

Exercise 1: Investigate the effect of the following commands:


(a) v(2) (b) sum = v + w (c) diff = v – w (d) vw = [v w] (e) vw(2:6) (f) v’

One way to generate a column vector is to take the transpose of a row vector, as you will
have found in exercise 1(f). Column vectors can be typed in directly in one of two ways. For
example, to enter the command vector

you can type


z = [1; 1; 0; 0]; or
z = [1
1
0
0];

Exercise 2: Investigate the effect of the following commands

(i) z’ (b) z*v (c) [v; w] (d) v*z (e) [z; v’] (f) z + v’
One way of creating matrices is by multiplying row and column vectors as seen in the above
exercises. There are various ways of entering matrices. For example, to enter the matrix

the most obvious ways are to type


M = [1 2; 3 4]; or
M = [1 2
3 4];
but there are more perverse ways such as
M = [[1 3]’[2 4]’];

Exercise 3
Investigate the effect of the following commands:

(a) N = inv(M) (b) M*N (c) I = eye(2) (d) M + I (e) M*z(1:2) (f) v(3:4)*M
(g) M(1,1) (h) M(1:2,1:2) (i) M(:,1) (j) M(2,:)

2
MNS UNIVERSITY OF ENGINEERING & TECHNOLOGY,
MATLAB INTRO
Lab Experiment #1

5. Built-in Functions and MATLAB help

You have already encountered some built-in functions. In addition to standard arithmetic
operators, such as “+” and “*”, you have met inv(A) that generates the inverse of A, and
eye(n) that generates the n-by-n identity matrix. MATLAB has a very large number of built-
in functions. To see the full list of those variables on your machine type
help
To get information on a specific function (“inv” for example) type
help inv
The help command is very useful. Most of the MATLAB built-in functions have very
descriptive names and are easily remembered or guessed.

Exercise 4:
Use the help command to find out about the following built-in functions and make up
your own simple examples:
1. ones 2. zeros 3. det 4. Linspace 5. Logspace

6. Graphs
The results of signal processing computations in MATLAB are huge matrices containing, for
example, frequency responses, which one would like to display in graphical form. We will go
through a simple example of generating data, plotting the graph, putting labels on the axes
etc.
We will plot the graph of
y = sin(t);
for t going from 0 to 20 seconds. First we need to generate a vector t containing the values of
time that we want to use. Type:
t=linspace(0,20,100);
which makes t into a row vector of 100 values from 0 to 20 inclusive. Then type
ys = sin(t);
To plot the set of points type:
Plot(t,ys)
The basic graph can be prettied up using the following self explanatory sequence of
commands:
xlabel(‘Time in seconds’)
ylabel(‘sin(t)’)
title(‘your Roll No.’)
grid

More than one set of points can be plotted on the same axes, and more than one graph can be
displayed on the screen at once.
The following exercise leads you though this:

Exercise 5:
1. Generate a vector yc containing the values of cos(t) for the same time range as
before.
2. From the “help” entry for “plot” find out how to get both ys and yc plotted against t
on the same axis.
3. From the “help” entry for “subplot” find out how to plot ys and yc plotted on two
separate graphs, one above the other.

Common questions

Powered by AI

MATLAB’s exercise-based learning approach is highly effective for new users, facilitating a hands-on understanding of its core functionalities and syntax. Exercises such as creating vectors, manipulating matrices, and plotting graphs encourage active engagement and immediate application of concepts . This approach caters to various learning styles, promoting deeper comprehension and retention of material. By encouraging experimentation and exploration, users quickly become familiar with MATLAB’s intuitive command structure and gain confidence in applying its features to real-world problems .

The MATLAB environment supports user interaction and exploration through comprehensive help features and a wide range of built-in functions. The help command provides detailed information about specific functions, enhancing the user’s ability to understand and utilize MATLAB’s capabilities effectively . Built-in functions such as inv(A) for matrix inversion or eye(n) for identity matrices simplify complex operations, while example exercises encourage users to explore these functions on their own . This user-centric design promotes learning and discovery, making MATLAB an intuitive tool for both novices and experienced users.

MATLAB handles the entry and manipulation of matrices and vectors without requiring variable declaration, accommodating both real and complex types. Commands such as entering a row vector using brackets (e.g., v = [2 4 7 5]) allow users to interact with these data structures directly . Other commands such as v(2) for accessing elements, or operations like v + w for addition, facilitate manipulation. Transposing with v' creates column vectors from row vectors, showcasing how MATLAB simplifies vector operations .

Using MATLAB’s interpretive mode for code execution allows users to enter commands one line at a time, which simplifies the process for beginners or for quick calculations . This mode provides immediate feedback and is ideal for interactive exploration and testing of ideas. In contrast, writing custom MATLAB programs can enhance the software's power and efficiency by allowing users to automate tasks and develop complex applications. Custom programming supports modularity and reusability, enabling efficient problem-solving processes in more elaborate projects and professional environments .

The ability to generate plots with multiple datasets on the same axes in MATLAB offers significant advantages for comparative analysis and visualization. This feature allows users to overlay different data trends and patterns within a single graph, enhancing interpretability and insight . Commands that facilitate this process include the plot command, which can accept multiple data series arguments to display them together. For instance, plotting ys and yc against t on the same axis provides a clear visual comparison of sine and cosine functions over the same time range .

MATLAB’s matrix operations underscore its capabilities as a numerical tool by offering straightforward commands for complex mathematical computations. For example, the operation inv(M) computes the inverse of a matrix M, while eye(n) generates an n-by-n identity matrix, both of which are fundamental tasks in linear algebra and engineering applications . Such operations are performed with efficiency and simplicity, making MATLAB particularly valuable for tasks that require reliable numerical precision and fast computation, highlighting its strengths as a matrix-focused software environment.

MATLAB is distinguished as a matrix laboratory due to its primary function of performing calculations on matrices, row vectors, and column vectors, which are fundamental to many scientific, engineering, and mathematical applications . This impacts its usability significantly in both academic and industry environments by providing a high-level, numerically oriented programming language that simplifies complex mathematical computations. Moreover, its built-in functions for matrix and vector operations enhance ease of use, allowing users to perform tasks like finding determinants or inverses of matrices with simple commands, making MATLAB a valuable tool for both learning and professional problem-solving .

Users can customize plot aesthetics in MATLAB by using commands that modify labels, titles, and add grid lines, such as xlabel, ylabel, title, and grid . These customization capabilities are crucial for data presentation as they enhance the clarity and visual appeal of graphs, making it easier for audiences to understand and interpret data. Effective aesthetics highlight key elements, facilitate communication, and ensure that data insights are accurately conveyed, which is essential for academic, industrial, and scientific communications .

MATLAB's flexibility in entering matrices through various notations aids its applicability across disciplines by accommodating diverse user preferences and problem requirements. For instance, matrices can be input in several formats, such as M = [1 2; 3 4] for a conventional method or using transposed vectors like M = [[1 3]'[2 4]'] to achieve similar results . This versatility allows users from different fields—such as engineering, physics, or finance—to integrate MATLAB seamlessly into workflows that require specific data representations and manipulations, thus broadening its utility and appeal.

MATLAB can be used for plotting graphs by generating vectors for dataset points and using simple plotting commands. For instance, one can create a vector t with linspace(0,20,100) to generate 100 time values between 0 and 20 seconds, followed by ys = sin(t) to calculate sine values . The plot(t,ys) command generates the graph, which can be customized with xlabel('Time in seconds'), ylabel('sin(t)'), and title('your Roll No.') for labeling and titling. The grid command adds a grid for better visual reference .

You might also like