Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more ➡
Standard view
Full view
of .
×
0 of .
Results for:
P. 1
Matlab Tutorial

# Matlab Tutorial

Ratings: 0|Views: 2,392|Likes:
Tutorial sobre: Matrices, funciones trigonometriítas y operaciones simbólicas.\
Idioma: Ingles Paginas:6 Valoración: Bueno Formato: pdf (Adobe Acrobat)
Tutorial sobre: Matrices, funciones trigonometriítas y operaciones simbólicas.\
Idioma: Ingles Paginas:6 Valoración: Bueno Formato: pdf (Adobe Acrobat)

### Availability:

See More
See less

12/03/2013

pdf

text

original

1 of 6
E E 338
Fall 2001
MATLAB Tutorial
1.
The Basics
\u2022MATLAB is an interactive software development tool intended to facilitate the
analysis and visualization of numerical data.
\u2022The basic object in MATLAB is the data matrix and the manipulation of these objects
generally follows the rules of matrix algebra.
\u2022Lines of program can be entered and executed one at a time in the Command Window
or as groups of commands from a script file.
\u2022A MATLAB script file is just a text file with the .m extension and can be produced
with any word processor.
\u2022 In the Command Window, the prompt for input is >>.
To enter a matrix the square brackets [ ] are used and it is usually assigned to a variable
name. So, for example, if
12 3 4
56 7 8
9 10 11 12
\u00e9
\u00f9
\u00ea
\u00fa
=\u00ea
\u00fa
\u00ea
\u00fa
\u00eb
\u00fb
A
We would proceed as follows:
>> A = [1 2 3 4; 5 6 7 8; 9 10 11 12]
The semicolon inside the brackets delimits the rows of the matrix.
Now if we type:
>> A
MATLAB would respond as:
A =
1
2
3
4
5
6
7
8
9
10
11
12
Now if we type:

>> A = [1 2; 3 4]; >> B = [1 1; 0 1]; >> C = A * B

2
MATLAB would respond as:
C =
1
3
3
7
>>
So thatC is the matrix product ofA andB. The semicolon at the end of a line is used to
suppress the output of the result of executing the command.
To input a row vector, the colon operator can be used:
>> x = [-5:15];
To convertx to a column vector, the transpose operator can be used:
>> y = x';
To do the dot product between two row vectorsx andw, we could type:
>> z = x * w';
2.
Variable Formats
\u2022Numeric
>> x = 5.3;
% scalars, vectors matrices etc.
\u2022String
>> y = 'this is text';
% used to label axes, plots etc.
\u2022 Lo gi c al

>> x = [1 2 3];
>> y = [3 2 1+3j];
>> z = x == y

z = 0 1 0
% z is a logical variable
\u2022 S ym b o l i c
>> x = sym('x')
% the string x becomes symbolic
>> y = diff(cos(x))
y = -sin x
% the derivative of cos x
3
3.
Predefined Variables
A number of useful variables have been predefined in MATLAB.
ans, i, j, pi, inf, eps, nan
A column vector containing the values of these variables could be produced by typing
>>v = [ans; i; j; pi; inf; eps; nan];
Complex numbers can be entered by typing
>>r = 2 - j * y;
% y must already be defined.
or
>>r = 2 - 3j;
% a convenient short form.
4.
Built-in Functions

MATLAB contains literally hundreds of built-in functions including the conventional
trigonometric, exponential functions, those that produce conventional plots and other
visuals displays and those that perform specialized operations such as Fourier and
Laplace transforms, Bode plots, statistical regression and so on. Generally the
elementary mathematical functions take matrices and complex numbers as arguments.

For example:

>> n = 0:99;
>> x = 2.54 * sin(.1*pi*n + pi/8);
>> subplot(2,2,1)
>> plot(n, x)
>> grid
>> m = 0:10;
>> z = -3.2 * exp(.1j*pi*m);
>> subplot(2,2,2)
>> stem(m, real(z), 'filled')
>> grid

0
20
40
60
80
100
\u22123
\u22122
\u22121
0123
0
2
4
6
8
10
\u22124
\u22122
024

## Activity (7)

### Showing

AllMost RecentReviewsAll NotesLikes