Professional Documents
Culture Documents
1. How to start:
a) Click the icon on the desktop;
b) Start->run->Matlab
2. Matlab Environment
a) Command window
b) Graphics window
c) Edit window
3. Exercises:
Do these exercises in the command window:
a) >>2+4
ans=
6
>>ans+5
ans=
11
Notice that MATLAB has automatically assigned the answer to a variable, ans. Thus, you
could use ans in a subsequent calculation.
b)
>>a=4
a=
4
>>b=6;
>>c=8,d=0;
c=
8
You can type several commands on the same line by separating them with commas or
semicolons. If you separate them with commas, they will be displayed, and if you use the
semicolon, they will not.
c)
>>a=8;A=12
Enter
>>a
Then, enter
>>A
MATLAB treats names in a case-sensitive manner-that is , the name a is not the same as the
name A.
d) Complex values
>>x=1+5*i
>>y=2+9*j
MATLAB allows the symbol j to be used to represent the unit imaginary number for input.
However, it always uses an i for display.
e) Predefined variables
>>pi
>>format long
>>pi
>>format short
>>pi
Some of the predefined variables
Column vector:
>>b=[2;4;6;8;10]
>>b=[2;
4;
6;
8;
10]
>>b=[2 4 6 8 10]
Matrices:
>>A=[1 2 3;4 5 6;7 8 9]
>>A=[1 2 3
456
7 8 9]
g) Colon Operator
>>t=1:5
>>t=1:0.5:3
>>t=10:-1:5
The colon can also be used as a wildcard to select the individual rows and columns of
a matrix.
>>A(2,:)
We can also use the colon notation to selectively extract a series of elements from
within an array.
>>t(2:5)
h) Linspace
The linspace function generates a row vector of equally spaced points.
linspace(x1,x2,n)
i) Logspace
The logspace function generates a row vector that is logarithmically equally spaced.
logspace(x1,x2,n)
h) Graphics
>>t =[0:2:20]
>>g=9.81;m=68.1;cd=0.25;
>>v=sqrt(g*m/cd)*tanh(sqrt(g*cd/m)*t)
>>plot(t,v)