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

Introduction To MATLAB

This document provides an introduction and overview of basic MATLAB commands and operations. Some key points: - It describes how to display information about MATLAB version and license, clear the screen, view demos and documentation. - Elementary operations are demonstrated like defining vectors and matrices, arithmetic operations, matrix inverse, transpose, and rank. - Commands for common math functions are shown like exponential, logarithm, trigonometric, and square root. - Basic plotting of functions is illustrated using tangent, cosine, and a combination function. - The document is intended to familiarize users with basic MATLAB syntax and capabilities through simple examples and commands.

Uploaded by

Mukt Shah
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)
24 views

Introduction To MATLAB

This document provides an introduction and overview of basic MATLAB commands and operations. Some key points: - It describes how to display information about MATLAB version and license, clear the screen, view demos and documentation. - Elementary operations are demonstrated like defining vectors and matrices, arithmetic operations, matrix inverse, transpose, and rank. - Commands for common math functions are shown like exponential, logarithm, trigonometric, and square root. - Basic plotting of functions is illustrated using tangent, cosine, and a combination function. - The document is intended to familiarize users with basic MATLAB syntax and capabilities through simple examples and commands.

Uploaded by

Mukt Shah
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/ 38

Introduction to MATLAB

Objective
Display Windows
Some basic commands:
 >> ver

MATLAB Version 7.8.0.347 (R2009a)


MATLAB License Number: 161051
Operating System: Microsoft Windows XP
Version 5.1 (Build 2600: Service Pack 3)
Java VM Version: Java 1.6.0_04-b12 with Sun
Microsystems Inc. Java HotSpot(TM) Client VM
mixed mode
 >> home it will clear the screen
 >> info About MATLAB

For information about The MathWorks, go to:


http://www.mathworks.com/company/aboutus/
ntact_us
or call +1 508 647 7000.
 >> whatsnew About MATLAB (notes)

 >> demo Live demos are available

 >> doc Same as the command


“whatsnew”

>> clc It will clear the screen


 >> lookfor keyword It will give the information about
“keyword”
 >> lookfor eigenvalues

condeig - Condition number with respect to eigenvalues.


eig - Eigenvalues and eigenvectors.
ordeig - Eigenvalues of quasitriangular matrices.
ordqz - Reorder eigenvalues in QZ factorization.
ordschur - Reorder eigenvalues in Schur factorization.
qz - QZ factorization for generalized eigenvalues.
eigs - Find a few eigenvalues and eigenvectors of a
matrix using ARPACK
eigshow - Graphical demonstration of eigenvalues and singular
values.
expmdemo3 - Matrix exponential via eigenvalues and eigenvectors.
>> date it will give the current date
ans = 07-Jul-2014

 >> clock it will show the time


ans = 1.0e+003 *
2.0140 0.0070 0.0070 0.0210 0.0580
0.0105
 >> computer
it will show the operating system
ans = PCWIN
 >> cputime
it will show the time of usage of MATLAB
ans = 17.7969

 >> quit it will quit show the time

 >> exit it will exit


Elementary operations
 >> a=10;
>> b=2;
>> c=a/b
c=5

>> A=[1 2 3 4] For row vector


A=
1 2 3 4
>> B=[1; 2; 3; 4]
For column vector
B=
1
2
3
4
 >> A=[1 2 3;4 5 6;7 8 9]
for matrix

A=
1 2 3
4 5 6
7 8 9
 >> A+3
ans =
4 5 6
7 8 9
10 11 12
 >> A-2
ans =
-1 0 1
2 3 4
5 6 7
 >> A*3
ans =
3 6 9
12 15 18
21 24 27
 >> A/2
ans =
0.5000 1.0000 1.5000
2.0000 2.5000 3.0000
3.5000 4.0000 4.5000
 >> A.^2
Element wise operation
ans =
1 4 9
16 25 36
49 64 81
 >> A^2
AXA
ans =
30 36 42
66 81 96
102 126 150
>> B=[1 1 1;2 2 2;3 3 3]
B=
1 1 1
2 2 2
3 3 3
 >> A*B
Product of two matrices
ans =
14 14 14
32 32 32
50 50 50
 >> A/B Not possible
Warning: Matrix is singular to working
precision.
ans =
NaN NaN Inf
NaN NaN Inf
NaN NaN Inf
 >> A./B Individual element division
ans =
1.0000 2.0000 3.0000
2.0000 2.5000 3.0000
2.3333 2.6667 3.0000
 >> A^B Not possible

??? Error using ==> mpower

At least one operand must be scalar.


 >> A.^B Individual element wise

ans =

1 2 3
16 25 36
343 512 729
>> C=[1 4;5 6] Inverse of a matrix
C=
1 4
5 6

>> X=inv(C)
X=
-0.4286 0.2857
0.3571 -0.0714
 >> abs(-1) For Absolute value
ans =
1
 >> X=inv(A)

X=
0.5000 -0.7500 2.0000
-1.0000 1.0000 -1.0000
0.5000 -0.2500 0
 >> X=inv(A)*B

X=
4.7500 4.2500 5.2500
-4.0000 -3.0000 -5.0000
1.2500 0.7500 1.7500
 >> sec(45)
ans = 1.9036

>> B= transpose(C)
B=
1 5
4 6

>> k = rank(A)
k= 3
 >> sqrt(361) Square root of a number
ans = 19
 >> exp(2) Exponential
ans = 7.3891
 >> exp(0)

ans = 1
 >> exp(-1)

ans = 0.3679
 >> exp(1)

ans = 2.7183
>> x = (-pi/2)+0.01:0.01:(pi/2)-0.01;
plot(x,tan(x)), grid on

100

80

60

40

20

-20

-40

-60

-80

-100
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
 x = -pi:0.01:pi;
plot(x,cos(x)),grid on

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
-4 -3 -2 -1 0 1 2 3 4
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
plot(x,y,'--rs','LineWidth',2,...
'MarkerEdgeColor','g',...
'MarkerFaceColor','b',...
'MarkerSize',10)
3

-1

-2

-3
-4 -3 -2 -1 0 1 2 3 4
 >> solve('x^2-2*x+1')

ans =

1
1

You might also like