Comercio y trafico de exclavos durante la colonia
Introduction to MATLAB
The purpose of this module1 is to review MATLAB for those that have used it before, and to provide a brief introduction to MATLAB for those that have not used it before. This is a "handson" tutorial introduction. After using this tutorial, you should be able to: • • • 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12 1.13 1.14 1.15 enter matrices make plots write simple m-files Background Using this tutorial Entering matrices The MATLAB workspace Complex variables Matrix multiplication Plotting More matrix stuff FOR loops and IF-THEN statements m-files Diary Toolboxes Limitations to Student MATLAB Contacting MATHWORKS Summary of Commands • • perform matrix operations use MATLAB functions
1 A good …ver más…
We can find the value of the third element in the z vector, z(3), by typing
» z(3) ans = 15
Notice that a new variable, ans, was defined automatically.
1.4 The MATLAB Workspace
We can view the variables currently in the workspace by typing
» who Your variables are:
1.4 The MATLAB Workspace
5
ans
x
y
z
leaving 621420 bytes of memory free.
More detail about the size of the matrices can be obtained by typing
» whos Name ans x y z Size 1 1 6 1 by by by by 1 6 1 6 Total 1 6 6 6 Complex No No No No
Grand total is (19 * 8) = 152 bytes, leaving 622256 bytes of memory free.
We can also find the size of a matrix or vector by typing
» [m,n]=size(x) m= 1 n= 6 where m represents the number of rows and n represents the number of columns. If we do not put place arguments for the rows and columns, we find
» size(x) ans = 1 6
Since x is a vector, we can also use the length command
» length(x) ans = 6
6
Module 1. MATLAB
It should be noted that MATLAB is case sensitive with respect to variable names. An X matrix can coexist with an x matrix. MATLAB is not case sensitive with respect to "built-in" MATLAB functions. For example, the length command can be upper or lower case
» LENGTH(x) ans = 6
Notice that we have not named an upper case X variable. See what happens when we try to find the length of X
» LENGTH(X) ??? Undefined function or variable. Symbol in question