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

MATLAB EXPERIMENT 1

Uploaded by

Aadil Ahmad
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)
34 views

MATLAB EXPERIMENT 1

Uploaded by

Aadil Ahmad
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/ 11

EXPERIMENT-I

1.1 Objectives

a. To Know the history and features of MATLAB


b. To Know the local environment of MATLAB

1.2 Introduction

This chapter is a brief introduction to MATLAB (an abbreviation of MATrix LABoratory)


basics, registered trademark of computer software, version 4.0 or later developed by the Math
Works Inc. The software is widely used in many of science and engineering fields. MATLAB
is an interactive program for numerical computation and data visualization. MATLAB is
supported on Unix, Macintosh and Windows environments. For more information on
MATLAB, contact The MathWorks.Com. A Windows version of MATLAB is assumed here.
The syntax is very similar for the DOS version. MATLAB integrates mathematical
computing, visualization, and a powerful language to provide a flexible environment for
technical computing. The open architecture makes it easy to use MATLAB and its
companion products to explore data, create algorithms and create custom tools, that provide
early insights and competitive advantages.

Known for its highly optimized matrix and vector calculations, MATLAB offers an intuitive
language for expressing problems and their solutions both mathematically and visually.
Typical uses include:
• Numeric computation and algorithm development.
• Symbolic computation (with the built-in Symbolic Math functions).
• Modelling, simulation and prototyping.
• Data analysis and signal processing.
• Engineering graphics and scientific visualization.

1.3 History

• Developed primarily by Cleve Moler in the 1970'sDerived from FORTRAN


subroutines LINPACK and EISPACK, linear and eigenvaluesystems.
• Developed primarily as an interactive system to access LINPACK and EISPACK.
• Gained its popularity through word of mouth, because it was not socially distributed.
• Rewritten in C in the 1980's with more functionality, which include plotting routines.
• The Math Works Inc. was created (1984) to market and continue development of
MATLAB.

1.4 Strengths

• MATLAB may behave as a calculator or as a programming language


• MATLAB combine nicely calculation and graphic plotting.
• MATLAB is relatively easy to learn
• MATLAB is interpreted (not compiled), errors are easy to fix
• MATLAB is optimized to be relatively fast when performing matrix operations
• MATLAB does have some object-oriented elements

1.5 Weaknesses

• MATLAB is not a general purpose programming language such as C, C++, or


FORTRAN
• MATLAB is designed for scientific computing, and is not well suitable for other
applications
• MATLAB is an interpreted language, slower than a compiled language such as C++
• MATLAB commands are specific for MATLAB usage. Most of them do not have a
direct equivalent with other programming language commands

1.6 Key Features

• It is a high-level language for numerical computation, visualization and application


development.
• It also provides an interactive environment for iterative exploration, design and
problem solving.
• It provides vast library of mathematical functions for linear algebra, statistics, Fourier
analysis, filtering, optimization, numerical integration and solving ordinary differential
equations.
• It provides built-in graphics for visualizing data and tools for creating custom plots.
• MATLAB's programming interface gives development tools for improving code
quality, maintainability, and maximizing performance.
• It provides tools for building applications with custom graphical interfaces.
• It provides functions for integrating MATLAB based algorithms with external
applications and languages such as C, Java, .NET and Microsoft Excel.

1.7 MATLAB's Power of Computational Mathematics

MATLAB is used in every facet of computational mathematics. Following are some


commonly used mathematical calculations where it is used most commonly:

• Dealing with Matrices and Arrays


• 2-D and 3-D Plotting and graphics
• Linear Algebra
• Algebraic Equations
• Non-linear Functions
• Statistics
• Data Analysis
• Calculus and Differential Equations
• Numerical Calculations
• Integration
• Transforms
• Curve Fitting
• Various other special functions

1.8 Uses of MATLAB

MATLAB is widely used as a computational tool in science and engineering encompassing


the fields of physics, chemistry, math and all engineering streams. It is used in a range of
applications including:

• Signal processing and Communications


• Image and video Processing
• Control systems
• Test and measurement
• Computational finance
• Computational biology

1.9 Understanding the MATLAB Environment

MATLAB development IDE can be launched from the icon created on the desktop. The main
working window in MATLAB is called the desktop. When MATLAB is started, the desktop
appears in its default layout:
Current Folder - This panel allows you to access the project folders and files.

Command Window - This is the main area where commands can be entered
at the commandline. It is indicated by the command
prompt (>>).

Workspace - The workspace shows all the variables created and/or imported from
files.
Command History - This panel shows or rerun commands that are entered
at the commandline.
You are now faced with the MATLAB desktop on your computer, which contains the prompt
(>>) in the Command Window. Usually, there are 2 types of prompt:

>>For full version


EDU> for educational version

Note:

1. To simplify the notation, we will use this prompt, >>, as a standard prompt sign,
though our MATLAB version is for educational purpose.
2. MATLAB adds variable to the workspace and displays the result in the Command
Window.

Managing workspace and file commands

Command Description
cd Change current directory
clc Clear the Command Window
clear (all) Removes all variables from the workspace
clear x Remove x from the workspace
copy file Copy file or directory
delete Delete files
dir Display directory listing
exist Check if variables or functions are defined
help Display help for MATLAB functions
look for Search for specified word in all help entries
mkdir Make new directory
move file Move file or directory
pwd Identify current directory
rmdir Remove directory
type Display contents of file
what List MATLAB files in current directory
which Locate functions and files
who Display variables currently in the workspace
whos Display information on variables in the workspace
Commonly used Operators and Special Characters

MATLAB supports the following commonly used operators and special characters:

Operator Purpose
+ Plus; addition operator.
- Minus; subtraction operator.
* Scalar and matrix multiplication operator.
.* Array multiplication operator.
^ Scalar and matrix exponentiation operator.
.^ Array exponentiation operator.
\ Left-division operator.
/ Right-division operator.
.\ Array left-division operator.
./ Array right-division operator.
: Colon; generates regularly spaced elements and represents an
entire row or column.
() Parentheses; encloses function arguments and array indices;
overrides precedence.
[] Brackets; enclosures array elements.
. Decimal point.
… Ellipsis; line-continuation operator
, Comma; separates statements and elements in a row
; Semicolon; separates columns and suppresses display.
% Percent sign; designates a comment and specifies formatting.
_ Quote sign and transpose operator.
._ Non-conjugated transpose operator.
= Assignment operator.

Note:
If you end a statement with a semicolon, MATLAB performs the computation, butsuppresses
the display of output in the Command Window.
Special Variables and Constants
MATLAB supports the following special variables and constants:

Name Meaning
ans Most recent answer.
eps Accuracy of floating-point precision.
i,j The imaginary unit √-1.
Inf Infinity.
NaN Undefined numerical result (not a number).
pi The number π

Naming Variables

Variable names consist of a letter followed by any number of letters, digits or underscore.
MATLAB is case-sensitive.
Variable names can be of any length; however, MATLAB uses only first N characters, where
N is given by the function namelengthmax.

Saving Your Work


The save command is used for saving all the variables in the workspace, as a file with .mat
extension, in the current directory.
For example, save myfile
You can reload the file anytime later using the load command. load myfile.

Example 1:

Example 2:
Example 3:

In the above example it creates a 1-by-1 matrix named ‘x’ and stores the value 3 in its
element.
Example 4:

In this example x is to find the square root of 25 it creates a 1-by-1 matrix named ‘x’and
stores the value 5 in its element
.
Note:
• Once a variable is entered into the system, you can refer to it later.
• Variables must have values before they are used.
• When you do not specify an output variable, MATLAB uses the variable ans, short
for
answer, to store the results of your calculation.

Example 5:
In the above example we have multiple assignments

You might also like