>>
MATLAB has en extensive on-line help facility. For example:
>> help exp
EXP Exponential.
EXP(X) is the exponential of the elements of X, e to the X.
See also LOG, LOG10, EXPM, ARITH, POW2.
By simply typing:
>> helpMATLAB will provide a list of commands that are available. If you do not know the exact command for the function you are after, another useful command is lookfor. This command works somewhat like an index. If you did not know the command for the exponential function was exp, you could type:
>> lookfor exponential EXP Exponential. EXPM Matrix exponential.The command demo gives an overview of the available demo programs. These might be useful if you wish to know more about certain aspects of MATLAB.
Simple calculations can be carried out in MATLAB. For example by typing
>> 2+2MATLAB gives the (correct!) response:
ans =
4
However, most calculations are carried out using variables . This is illustrated below:
>> x = 2 >> z = x+xThe response is:
x =
2
z =
4
Actually we can suppress MATLAB from echoing to the screen by adding a
semicolon (;) after each line. For example
>> x = 2; >> z = x+xThis time the response is:
z =
4
>> who Your variables are: ans x zMore detail about the size of the matrices can be obtained by typing:
>> whos
Name Size Elements Bytes Density Complex
ans 1 by 1 1 8 Full No
x 1 by 1 1 8 Full No
z 1 by 1 1 8 Full No
Grand total is 3 elements using 24 bytes
Sometimes it is desirable to clear all the variables in a workspace. This
is done simply by typing:
>> clearMore frequently you may wish to clear a particular variable, such as x :
>> clear x
There are two ways of generating your own MATLAB code: 1) script files and 2) function routines. Function routines will be considered later in this course. We will start by initially just considering script files:
% My first program x = 2.0; y = 3*sqrt(x) -7
Click HERE for next section.