Escolar Documentos
Profissional Documentos
Cultura Documentos
Lecture 2
Description
The simplest way to create simple vectors, not convenient for complex vectors
Example
line = [1 3 5] line = 1 3 5 line = 1:0.4:5 line = Columns 1 through 9 1.00 1.40 1.80 2.20 2.60 3.00 3.40 3.8 4.20 Columns 10 through 11 4.60 5.00
array _ name xi : d : x f
Where xi = the initial element in the array. xf = the destination element in the array. d = the step size (Default value=1) xi could be bigger than xf, but d should be ve in this case Where xi = the initial element in the array. xf = the destination element in the array. n = the number of elements in between If n is not provided, the default value is 100
line = linspace (1,5,11) line = Columns 1 through 9 1.00 1.40 1.80 2.20 2.60 3.40 3.80 4.20 Columns 10 through 11 4.6000 5.0000
3.00
on ones (k , l )
on = ones(2,3) on = 1 1 1 1
1 1
dimensions m x m
All variables in MATLAB are arrays. A scalar variable is an array of single element.
2.
The array variable is defined by the input when it is assigned. Therefore there is no need to define the size of an array, since it will take the size of the input automatically.
3.
You can still perform any operation on any array to change its name, contents, dimensions, or type.
4.
Examples
>> A = 5; B = power (A,3); >> C = [A, 27, sqrt (B), B - A^2] C= 5.0000 27.0000 11.1803 100.0000 >> C(4) = 99 C= 5.0000 27.0000 11.1803 99.0000 >> C(6) = 4 C= 5.0000 27.0000 11.1803 99.0000 >> C (2:5) ans = 27.0000 11.1803 99.0000 >> C (1:2:5) ans = 5.0000 11.1803 % define two variables A and B % define an array C of 4 elements
% add two elements to the existing C array, the 5th is zero by default 0 4.0000 % chose elements 2, 3, 4 and 5
>> E = [D(2:3,2:4)] E= 80 60 40 2 3 4
>> F = [C(1:3);E(1,:)] F= 5.0000 27.0000 11.1803 80.0000 60.0000 40.0000 >> F(2,2) = F(2,1) - F(2,3) + 10*E(2,3) F= 5.0000 27.0000 11.1803 80.0000 80.0000 40.0000
% define matrix F thats a combination of the 1st three elements of C % as its 1st row, and the complete 1st row of E as its 2nd row
>> K = [J F]
>> L = [F ; J]
>> L (1:3,:) = [ ]
L=
0.0098 L= 3 4 3.0000 4.0000 >> L (1) = [ ]
>> [row_J , column_J] = size (J)% return the size of J row_J = 2 column_J = 3 >>M = rand (3) M= 0.9218 0.7382 0.1763 0.4057 0.9355 0.9169 0.4103 0.8936 0.0579 % create a random matrix M of dimensions 3x3 >> O = [6 -12 20] O= 6 -12 20
string _ name char (' string1' , ' string 2' , ' string 3' ,...)
>> student_info = char ('student info= , student_name , 'Grade , 'B+') student_info = student name Robert Smith Grade B+
0.2635 0.5761 0.6932 0.7475 -0.5105 -0.0679 % check that orth (Q)T x orth (Q) is the eye (rank (Q)) 0.0000 0.0000 0.0000 1.0000
>> S = R * R R= 1.0000 -0.0000 -0.0000 -0.0000 1.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 1.0000 0.0000
How long does it take you to find orth (Q)? How many
Orthonormalization process