You are on page 1of 7

)(Vectors

-1 Row Vectors
) (commas ) . (spaces
) (length of vector .
] [ .

]>>V=[1 3 5
V=1 3 5

]>>W=[2,4,8
W=2 4 8

:
])>>K=[0 9, sqrt(4
K=0 9 2

.
]>>V2=[3+ 4 5
V2=7 5
]>>V3=[3 +4 5
V3=3 4 5

length :
]>>GH=[9,8,sin(pi/6),2
= GH
2.0000

0.5000

8.0000

9.0000

)>>length(GH
ans= 4
:

>>V=[1 3 5]; V3=[3 +4 5]; V+V3


ans= 4 7 10
)(scalar

>>V4=3*V
V4= 3 9 15
>>V5=2*V-3*V3
V5= -7 -6 -5

:
>>V=[1,3,5];V2=[3+ 4 5];B=V-V2
??? Error using ==> minus
Matrix dimensions must agree.
:
;]>>W=[1 2 3], Z=[8 9
]>>CK=[2*Z,-W
CK = 16 18 -1 -2 -3
) (sort :
)>>sort(CK
ans= -3 -2 -1 16 18
.
] >>r=[ 10 12 6
>>r(2)=-8
)>>r(3
>>r(2)=r(1)+4
10 12 6
10 -8 6
6
10 14 6

(Colon Notation ):

a:b:c a
c
.b
>>1:4
1 2 3 4
>>3:7
3 4 5 6 7
>>G=0.32:0.1:0.6
G= 0.3200 0.4200 0.5200
>>-1.4:-0.3:-2
ans= -1.4000 -1.7000 -2.0000
>>Y=20:-2:10
Y= 20 18 16 14 12 10

Extracting Bits of a vector


.
-7

-5

]>>R5=[1:2:6, -1:-2:-7
R5= 1 3 5 -1 -3
)>>R5(3:6
ans= 5 -1 -3 -5
)>>R5(1:2:7
ans= 1 5 -3 -7
)>>R5(6:-2:1
ans= -5 -1 3
>>FG=R5(6:-2:1)*2
FG= -10 -2 6

Column Vectors

);(.
]>>C=[1;3;5
C= 1
3
5
>>C3=2*C-3*C
C3= -1
-3
-5
]>>VD=[1:2:6 ; -2:-1:-4 ; 6:-2:2
VD= 1 3 5
-2 -3 -4
6 4 2

.

Transposing :
)(.
]>>K=[1 -2 3
>>K
K= 1 -2 3
1
-2
3
>>C=[1;3;5],C
C= 1
3
5
1 3 5
>>T=K+2*C
T= 3 4 13
>>XV=5*K-2*C
XV= 3
-16
5

You might also like