# experiment basic matlab

Post on 26-Dec-2015

44 views

Embed Size (px)

DESCRIPTION

matlabTRANSCRIPT

EXPERIMENT-01INTRODUCTION TO MATLAB

AIM- To understand MATLAB basic features and built in functions available in MATLAB.Date:-Name:-

EQUIPMENT AND SOFTWARE: Personal Computer loaded with MATLAB 7.1

OPERATING SYSTEM: Windows XPTHEORY: MATLAB (matrix laboratory) is a fourth-generation high-level programming language and interactive environment for numerical computation, visualization and programming. MATLAB is developed by MathWorks.It allows matrix manipulations; plotting of functions and data; implementation of algorithms; creation of user interfaces; interfacing with programs written in other languages, including C, C++, Java, and Fortran; analyze data; develop algorithms; and create models and applications.It has numerous built-in commands and math functions that help you in mathematical calculations, generating plots and performing numerical methods. Local Environment SetupIf you are still willing to set up your environment, let me tell you a secret, setting up MATLAB environment is a matter of few clicks. However, you need to download the installer from here: MathWorks provides the licensed product, a trial version and a student version as well. You need to log into the site and wait a little for their approval.Once you get the download link, as I said, it is a matter of few clicks:

Figure 1.1 Installation window Understanding the MATLAB Environment:You can launch MATLAB development IDE from the icon created on your desktop. The main working window in MATLAB is called the desktop. When you start MATLAB, the desktop appears in its default layout: Figure 1.2: Organisation of the Matlab windowMATLAB : Help The most important function for learning MATLAB on your own.

MATLAB : Customization File -> PreferencesThis feature allows us to personalize our MATLAB experience.

MATLAB : Basic components of Environment MATLAB has the following basic window components : Launch Pad WindowTo access all MATLAB services and tool boxes. Command WindowTo execute commands in MATLAB environment. Current Directory WindowTo quickly access files on the MATLAB path. Figure WindowTo display graphical output from MATLAB code. Workspace WindowTo view variable definitions and variable memory allocations M - File Editor / Debugger WindowTo write M-Files( includes color coded syntax features).To debug M-Files interactively ( break points). MATLAB Path WindowTo add and delete folders to the MATLAB path. Command History WindowDisplays all commands issued in MATLAB since the last session ( for verification)

Commonly used Operators and Special CharactersMATLAB supports the following commonly used operators and special characters:OperatorPurpose

+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.

._Nonconjugated transpose operator.

=Assignment operator.

Special Variables and Constants MATLAB supports the following special variables and constants:NameMeaning

ansMost recent answer.

epsAccuracy of floating-point precision.

i,jThe imaginary unit -1.

InfInfinity.

NaNUndefined numerical result (not a number).

PiThe number

Features of MATLAB Following are the basic features of MATLAB: 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 and 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 Uses of MATLABMATLAB 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 BiologyRESULT: MATLAB basic features and built in functions were practiced thoroughly.VIVA VICE:-1. What is the Full Form Of MATLAB?2.What is the working of Command Window?3.What is NaN and eps? EXPERIMENT-02

VARIABLES AND COMMANDS IN MATLAB

AIM- To understand Variables and commands in MATLABDate:-Name:-EQUIPMENT AND SOFTWARE: Personal Computer loaded with MATLAB 7.1

OPERATING SYSTEM: Windows XP

THEORY: 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.

Basic Commands

Save command : 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

load command: You can reload the file anytime later using the load command.In MATLAB environment, every variable is an array or matrix.You can assign variables in a simple way. For example, x = 3 % defining x and initializing it with a value

Multiple Assignments : You can have multiple assignments on the same line.For example, a = 2; b = 7; c = a * b;Long Assignments : Long assignments can be extended to another line by using an ellipses (...).For example, initial_velocity = 0; acceleration = 9.8; time = 20; final_velocity = initial_velocity ... + acceleration * time Commands for Managing a SessionMATLAB provides various commands for managing a session. The following table provides all such commands:CommandPurpose

ClcClears command window.

ClearRemoves variables from memory.

ExistChecks for existence of file or variable.

HelpSearches for a help topic.

LookforSearches help entries for a keyword.

QuitStops MATLAB.

WhoLists current variables.

WhosLists current variables (long display).

Commands for Working with the SystemMATLAB provides various useful commands for working with the system, like saving the current work in the workspace as a file and loading the file later.It also provides various commands for other system-related activities like, displaying date, listing files in the directory, displaying current directory, etc.The following table displays some commonly used system-related commands:CommandPurpose

cdChanges current directory.

dateDisplays current date.

deleteDeletes a file.

dirLists all files in current directory.

loadLoads workspace variables from a file.

pathDisplays search path.

pwdDisplays current directory.

saveSaves workspace variables in a file.

typeDisplays contents of a file.

whatLists all MATLAB files in the current directory.

The format function has the following forms used for numeric display:Format FunctionDisplay up to

format shortFour decimal digits (default).

format long16 decimal digits.

format short eFive digits plus exponent.

format long e16 digits plus exponents.

format bankTwo decimal digits.

format +Positive, negative, or zero.

format ratRational approximation.

Vector, Matrix and Array CommandsThe following table shows various commands used for working with arrays, matrices and vectors:CommandPurpose

lengthComputes number of elements.

linspaceCreates regularly spaced vector.

logspaceCreates logarithmically spaced vector.

maxReturns largest element.

minReturns smallest element.

prodProduct of each column.

reshapeChanges size.

sizeComputes array size.

sortSorts each column.

sumSums each column.

eyeCreates an identity matrix.

onesCreates an array of ones.

zerosCreates an array of zeros.

crossComputes matrix cross products.

dotComputes matrix dot products.

detComputes determinant of an array.

invComputes inverse of a matrix.

rankComputes rank of a matrix.

Plotting CommandsMATLAB provides numerous commands for plotting graphs. The following table shows some of the commonly used commands for plotting:CommandPurpose

axisSets axis limits.

gridDisplays gridlines.

plotGenerates xy plot.

printPrints plot or saves plot to a file.

titlePuts text at top of plot.

xlabelAdds text label to x-axis.

ylabelAdds text label to y-axis.

axesCreates axes objects.

closeCloses the current plot.

close allCloses all pl