Matlab Basics
- Vectors
a = [1 2 3 4 5 6 9 8 7]
- Matrices
Are entered as
A = [1 2 3 4;5 6 7 8;9 10 11 12] semi-colon seperates the rows
and shows up as :
A =
1 2 3 4
5 6 7 8
9 10 11 12
To generate a random matrix use rand(N,M) to give an NxM matirx.
>> rand(3,5)
ans =
0.8147 0.9134 0.2785 0.9649 0.9572
0.9058 0.6324 0.5469 0.1576 0.4854
0.1270 0.0975 0.9575 0.9706 0.8003
use eye(N) to generate the NxN identity matrix
>> eye(3)
ans =
1 0 0
0 1 0
0 0 1
- Plotting
Functions of one variable
To make a graph of y = sin(x) on the interval x = 0 to x = 10 we do the following:
>> x = 0:.3:10; >> y = sin(x); >> plot(x,y)
or x=0 to 2*pi
>> x = 0:.3:2*pi; >> y = sin(x); >> plot(x,y)