












































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of vector operations and matrix creation in matlab. It covers topics such as creating vectors, vector addition, scalar multiplication, vector length, and matrix creation. It also explains the difference between row and column vectors and the use of the colon operator for matrix indexing.
Typology: Slides
1 / 52
This page cannot be seen from the preview
Don't miss anything!













































Use the Transpose operator (‘) to make a COLUMN Vector
p = [ 3 , 7 , 9 ] Create Col-Vector Directly with SEMICOLONS
>>p = [3,7,9] p = 3 7 9
The TRANSPOSE Operation Swaps Rows↔Columns
>>p = [3,7,9]' p = 3 7 9
p
>>g = [3;7;9] g = 3 7 9
>> s =[-11:-6] s = -11 -10 -9 -8 -7 - >> t = [-11:1:-6] t = -11 -10 -9 -8 -7 -
>> linspace(5,8,31) = >> [5:0.1:8]
Calculate the Power of 10 increment
∆ p = ( b − a ) ( n − 1 )
In this case
( ( )) ( ) 3 5 0. 6
2 1 6 1 = =
∆ p = − − −
In this Case k Power yk 1 -1 0. 2 -0.4 0. 3 0.2 1. 4 0.8 6. 5 1.4 25. 6 2 100.
for k = 1→6, then the k th^ y-value
logspace Example (alternative)
Take base-10 log of the above
Calc Spacing Between Adjacent Elements with diff command
>> yLog10 = log10(y) yLog10 = -1.0000 -0.4000 0.2000 0.8000 1.4000 2.
>> yspc = diff(yLog10) yspc = 0.6000 0.6000 0.6000 0.6000 0.
By Pythagoras Find vector a magnitude
2 2 2 2
2 2 2
(^2 22) and
a x y z
a w z
w x y
= + +
= +
= + so
Thus the box diagonal
>> a =[2,-4,5]; >> length(a) ans = 3 >> % the Magnitude M = norm(a) >> Mag_a = norm(a) Mag_a =
>> abs(a) ans = 2 4 5
3D Vector Length Example
% Bruce Mayer * ENGR % 25Aug09 * Lec % file = VectorLength_0908.m % NOTE: using “norm” command is much easier % % Find the length of a Vector AB with %% tail CoOrds = (0, 0, 0) %% tip CoOrds = (2, 1, -5) % % Do Pythagorus in steps vAB = [2 1 -5] % define vector sqs = vAB.*vAB % sq each CoOrd sum_sqs = sum(sqs) % Add all sqs LAB = sqrt(sum_sqs) % Take SQRT of the sum- of-sqs
=
3 12 15
8 4 9
16 3 7
2 4 10
M
VECTORS are SPECIAL CASES of matrices having ONE ROW or ONE COLUMN.
M contains
16 3 7
2 4 10 A
spaces or commas separate elements in different columns , whereas semicolons separate elements in different rows.
The Command
>> D = [[1,3,5]; [7 9 11]] D = 1 3 5 7 9 11
Note the use of
Make Matrix Example
>> r1 = [1:5] r1 = 1 2 3 4 5 >> r2 = [6:10] r2 = 6 7 8 9 10 >> r3 = [11:15]r3 = 11 12 13 14 15 >> r4 = [16:20]r4 = 16 17 18 19 20
r5 =>> r5 = [21:25]
>> A = [r1;r2;r3;r4;r5]^21 22 23 24 A = 1 2 3 4 5
116 127 138 149 1015 (^1621 1722 1823 1924 )