ATLAB Tutorial: Presented By: Sanjay Dubey Teaching Assistant
ATLAB Tutorial: Presented By: Sanjay Dubey Teaching Assistant
ATLAB Tutorial: Presented By: Sanjay Dubey Teaching Assistant
Presented By:
Sanjay Dubey
Teaching
Assistant
1
Contents
1. Session One
What is MATLAB?
MATLAB Desktop
Matrix
Numerical Arrays
String Arrays
Elementary Math
Logical Operators
Math Functions
Polynomials
Graphics Fundamentals
2D plotting
2
What is MATLAB?
• high-performance software
• Computation
• Visualization
• Easy-to-use environment.
• high-level language (independent to computer
type)
• Data types
• Functions
• Input/output
• Graphics
4
MATLAB Desktop Tools
• Command Window
• Command History
• Help Browser
• Workspace Browser
• Editor/Debugger
6
General Functions
8
Basic Operation symbol
Calculations at the Command Line
7
Task 1
>> x=0.7854-(0.7854)^3/(1*2*3)+0.785^5/(1*2*3*4*5)
Ans:
x=
0.7071
Subtraction:
>> D = A – B
Multiplication:
>> E = A * B (Matrix multiplication)
>> E = A .* B (Element wise multiplication, A and B same size)
Division:
Left Division and Right Division
>> F = A . / B (Element wise division)
>> F = A / B = A*inv(B) (A * inverse of B)
>> F = A . \ B (Element wise division)
>> F = A \ B=inv(A)*B (inverse of A * B)
10
Creating Array
Other way of Creating Array
Creating Array : Character
Character Arrays (Strings)
• Created using single quote delimiter (')
» str = 'Hi there,'
str =
Hi there,
» str2 = 'Isn't MATLAB great?'
• Each
str2 =
character is a separate matrix element
(16 bits of memory per character)
Isn't MATLAB great?
15
Array Operation
Selecting Rows and Columns
13
Array Operation
Generating basic matrices
Matrix with ZEROS:
>> A = zeros(m, n)
IDENTITY Matrix:
>> I = eye(m, n)
m Rows
n Columns
zeros, ones, eye Matlab functions
14
Task 3
>> a=[5 35 43; 4 76 81; 21 32 40]
What happen if
you multiply
C= A*B
C=A.*B???
Array Multiplication vs Element Mul.
Elementary Math
•Logical Operators
•Math Functions
16
Logical Operations
= = equal to
> greater than
~ not
& and
| or
isfinite(), etc. . . .
all(), any()
find
17
Plotting
Task 7
>> x=[1 2 3 5 7 7.5 8 10];
>> y=[2 6.5 7 7 5.5 4 6 8];
>> plot(x,y)
Title
Ylabel
Grid
Legend
Xlabel
24
Programming and
Application
Development
25
Script and Function Files
Script and Function Files
• Script Files
• Work as though you typed commands into
MATLAB prompt
• Variable are stored in MATLAB workspace
• Function Files
• Let you make your own MATLAB Functions
• All variables within a function are local
• All information must be passed to functions as
parameters
• Subfunctions are supported
26
Task 8
x=[10:0.1:22];
y=95000./x.^2;
xd=[10:2:22];
yd=[950 640 460 340 250 180 140];
plot(x,y,'-','LineWidth',1.0)
xlabel('DISTANCE (cm)')
ylabel('INTENSITY (lux)')
title('\fontname{Arial}Light Intensity as a Function of
Distance','FontSize',14)
Plot
23
Getting more help
• Contact http://www.mathworks.com/support
• You can find more help and FAQ about
mathworks products on this page.
• Contact comp.soft-sys.matlab Newsgroup
• Using Google Groups Page to Access this page
http://groups.google.com/
33