You are on page 1of 19

Shashank 2819394

PROGRAM :1
AIM: To study MATLAB environment and to familiarize with Command window,
History, Workspace,Current Directory, Figure window, Edit window, Shortcuts, Help
files.

Introduction
 MATLAB stands for MATrix LABoratory.
 A special purpose computer program optimized to perform engineering and scientific
calculations.
 It is a Technical programming language.
 It Provide a very extensive library of predefined functions to make technical
programming task easier and more efficient.
 Easy to use.
 MATLAB is Multi-paradigm.

The MATLAB Environment

MATLAB Desktop integrates may tools for managing files, variables and application
within the MATLAB environment.
 Command window
 Command History
 Workspace
 Current Directory
 Figure window
 Edit window
 Shortcuts
 Help files

o Command window

This is the main area where command can be entered at the command line. It is indicated by
command prompt (>>), the prompt indicates that MATLAB is ready to accept input from us.

o Command History

The command history window displays a log of statement that you run in current and
previous MATLAB session. The command history list the time and date of each session in
the short date format for your operating system.

MATLAB/IT
Shashank 2819394

o Workspace

The workspace contains variables that you create or import into MATLAB from data files or
other programs. we can view and edit the content of workspace in workspace browser or in
command windows

o Current Directory

The current folder is a reference location that MATLAB uses to find files. This panel allow to
access the project folder and files.

 Figure window

MATLAB/IT
Shashank 2819394
MATLAB directs graphics output to a window that is separate from the
command window. In MATLAB, this window is referred to as figure.
Graphics functions automatically create new windows if none currently exist.
If a figure windows already exits, MATLAB uses that windows.

o Edit window

MATLAB Editor window is a simple text editor where you can load, edit
and save complete MATLAB programs. The editor window also has a menu
command (debug/run) which allows you to submit the program to the
command windows. It is used to create or modify M-file.

o Shortcuts

To view or modify the current set of keyboard shortcuts, use the Keyboard
Shortcuts Preferences panel. To open the Keyboard Shortcuts Preferences
panel, go to the Home tab, and in the Environment section, click Preferences.
Then, select MATLAB > Keyboard > Shortcuts.

 Helpfiles

Practical 2
Write a MATLAB program to calculate the following expression and round the answer to
nearest integer.

MATLAB/IT
Shashank 2819394
a) C=5x^2+y^2 where x=2, y=4

II. b=3sinx+4cosx+3ey

PROGRAM :3
AIM: Datatypes, Constants and Variables, Character constants, operators, Assignment
statements.
 Numeric Types
Integer and floating-point data

MATLAB/IT
Shashank 2819394
 Characters and Strings
Text in character arrays and string arrays

• Dates and Time


Arrays of date and time values that can be displayed in different formats

• Categorical Arrays
Arrays of qualitative data with values from a finite set of discrete, nonnumeric data

• Tables
Arrays in tabular form whose named columns can have different types

• Timetables
Time-stamped data in tabular form

• Structures
Arrays with named fields that can contain data of varying types and sizes

• Cell Arrays
Arrays that can contain data of varying types and sizes

• Function Handles
Variables that allow you to invoke a function indirectly

• Map Containers
Objects with keys that index to values, where keys need not be integers.

• Time Series
Data vectors sampled over time

• Data Type Identification


Determine data type of a variable

• Data Type Conversion


Convert between numeric arrays, strings and character arrays, dates and times, cell
arrays, structures, or tables

Constant & Variables:-

It is possible to create named constants as part of a class or package in MATLAB versions 7.6
(R2008a) and above. The ability to create constant variables is not available in previous
versions of MATLAB. To work around this, you can create a function with the same name as
the constant that returns its value. Operators:-

MATLAB/IT
Shashank 2819394

PROGRAM :4
AIM: Control Structures: For-loops, While, If-control structures, Switch, Break, Continue
statements, Input-Output functions, Reading and Storing Data.

MATLAB/IT
Shashank 2819394

For: A for loop is a repetition control operation that allows us to accurately write a loop that
wants to perform a particular number of times.
Syntax
1. for index=values
2. statement
3. .
4. .
5. end

while: The while loop repeatedly executes statements while a specified statement is true.
Syntax
1. while expression
2. statements
3. end

If: If evaluates a logical expression and executes a group of statements based on the value
of the expression. Syntax of If Statement if expression 1 statement1
elseif expression
2 statement 2 else
statement 3 end

MATLAB/IT
Shashank 2819394

Switch, case, and otherwise: Switch executes certain statements based on the value of
a variable or expression. Its basic form is Syntax
switch switch
expression case case
expression statement s
case case expression
statements
.
.
.
otherwise
statements
end

break: The break statement terminates execution of for or while loops. Statements in the
loop that appear after the break statement are not executed.

MATLAB/IT
Shashank 2819394

continue: The continue statement is used for passing control to the next iteration of a for or
while loop.

MATLAB/IT
Shashank 2819394

PROGRAM :5
AIM: Vectors and Matrices, command to operate on vectors and matrices, matrix
Manipulations.

Vectors and Matrices: -

Defining a matrix is like defining a vector. To define a matrix,we can treat it like a column of
row vectors (note that the spaces are required!):

We can also treat it like a row of column vectors:

Command To Operate On Vectors And Matrices:- There are also routines that let you find solutions
to equations. For example, if A x = b and you want to find x, a slow way to find x is to simply invert
A and perform a left multiply on both sides (more on that later). It turns out that there are more
efficient and more stable methods to do this (L/U decomposition with pivoting, for example).
Matlab has special commands that will do this for you.Before finding the approximations to linear
systems, it is important to remember that if A and B are both matrices, then AB is not necessarily
equal to BA. To distinguish the difference between solving systems that have a right or left multiply,
Matlab uses two different operators, / and \. Examples of their use are given below. It is left as an
exercise for you to figure out which one is doing what.

MATLAB/IT
Shashank 2819394

Finally, sometimes you would like to clear all of your data and start over. You do this with the
clear command. Be careful though, it does not ask you for a second opinion and its results are
final.

Matrix Manipulations: -

Just use [] for any column or row that you want to remove.

MATLAB/IT
Shashank 2819394

MATLAB/IT
Shashank 2819394

PROGRAM :6
AIM: Arithmetic operations on Matrices, Relational operations on Matrices, Logical
operations on Matrices.

Arithmetic operations on Matrices: -

Arithmetic functions include operators for simple operations like addition and
multiplication, as well as functions for common calculations like summation, moving
sums, modulo operations, and rounding.

Relational operations on Matrices: -

Relational operators compare the elements in two arrays and return logical true or
false values to indicate where the relation holds

ADDITION

+ Addition or append strings


Sum Sum of array elements
Cumsum Cumulative sum
MOVSUM Moving sum
Subtraction

- Subtraction

MATLAB/IT
Shashank 2819394

Diff Differences and approximate derivatives


Multiplication

.* Multiplication
* Matrix multiplication
Prod Product of array elements
Cumprod Cumulative product
Pagemtimes Page-wise matrix multiplication
Division

./ Right array division


.\ Left array division
/ Solve systems of linear equations xA = B for x
\ Solve systems of linear equations Ax = B for x
Powers

.^ Element-wise power
^ Matrix power
Transpose

.’ Transpose vector or matrix


‘ Complex conjugate transpose
Pagetranspose Page-wise transpose
Pagectranspose Page-wise complex conjugate transpose
Array Sign

Uminus Unary minus


uplus Unary plus

MATLAB/IT
Shashank 2819394

Relational operations on Matrices: -


Relational operators compare the elements in two arrays and return logical true or
false values to indicate where the relation holds
== Determine equality
>= Determine greater than or equal to
> Determine greater than
<= Determine less than or equal to
< Determine less than
~= Determine inequality
isequal Determine array equality
isequaln Determine array equality, treating NaN values as
equal

MATLAB/IT
Shashank 2819394

Logical operations on Matrices: -

The logical data type represents true or false states using the numbers 1 and 0,
respectively. Certain MATLAB® functions and operators return logical values to indicate
fulfilment of a condition. You can use those logical values to index into an array or
execute conditional code.

Short-circuit &&, || Logical operations with short-circuiting


& Find logical AND
~ Find logical NOT
| Find logical OR
xor Find logical exclusive-OR
All Determine if all array elements are nonzero or true
Any Determine if any array elements are nonzero
false Logical 0 (false)
Find Find indices and values of nonzero elements
Islogical Determine if input is logical array
Logical Convert numeric value to logicals
True Logical 1 (true )

MATLAB/IT
Shashank 2819394

PROGRAM :7
AIM: If x = [1 4;8 3], find: 
the inverse matrix of x.

MATLAB/IT
Shashank 2819394

the transpose of x.

Determinant of x

MATLAB/IT
Shashank 2819394

MATLAB/IT

You might also like