0% found this document useful (0 votes)
9 views

LAB 1.m

The document contains examples of operations on matrices and vectors in MATLAB including: defining matrices A and B; transposing and finding the sum and diagonal of A; assigning a value to an element of A; defining and assigning values to matrices S and B; defining a vector using a range; and creating matrices by applying functions like logarithms and exponents to vectors.

Uploaded by

Mitchell Tidan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

LAB 1.m

The document contains examples of operations on matrices and vectors in MATLAB including: defining matrices A and B; transposing and finding the sum and diagonal of A; assigning a value to an element of A; defining and assigning values to matrices S and B; defining a vector using a range; and creating matrices by applying functions like logarithms and exponents to vectors.

Uploaded by

Mitchell Tidan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

>> A= [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]

A=

16 3 2 13

5 10 11 8

9 6 7 12

4 15 14 1

>> B= [16 3 2 13 1 3; 5 10 11 8 11 8; 9 6 7 12 11 12; 4 15 14 1 12 13; 12 3 2 4 12 11; 12 11 10 4 13 14]

B=

16 3 2 13 1 3

5 10 11 8 11 8

9 6 7 12 11 12

4 15 14 1 12 13

12 3 2 4 12 11

12 11 10 4 13 14

>> A'

ans =

16 5 9 4

3 10 6 15

2 11 7 14

13 8 12 1

>> Sum A

Undefined function or variable 'Sum'.


Did you mean:

>> sum (A)

ans =

34 34 34 34

>> sum (A')

ans =

34 34 34 34

>> sum (A')'

ans =

34

34

34

34

>> diag (A)

ans =

16

10

1
>> sum(diag(A))

ans =

34

>> A (3,5) = 17

A=

16 3 2 13 0

5 10 11 8 0

9 6 7 12 17

4 15 14 1 0

>> S (6,7)=18

S=

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 18

>> B = S

B=
0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 18

>> S=B

S=

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 18

>>

>> M = [1:10]

M=

1 2 3 4 5 6 7 8 9 10

>> M = [100:-2:40]

M=

100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60
58 56 54 52 50 48 46 44 42 40
>> 0:pi/4:pi

ans =

0 0.7854 1.5708 2.3562 3.1416

>> n = (0:9)';

>>

>> n = (0:9)'

n=

>> Pows = [n n.^2 2.^n]

Pows =

0 0 1

1 1 2

2 4 4
3 9 8

4 16 16

5 25 32

6 36 64

7 49 128

8 64 256

9 81 512

>> x = (1:0.1:2)'

x=

1.0000

1.1000

1.2000

1.3000

1.4000

1.5000

1.6000

1.7000

1.8000

1.9000

2.0000

>> logs = [x log10(x)]

logs =

1.0000 0

1.1000 0.0414

1.2000 0.0792
1.3000 0.1139

1.4000 0.1461

1.5000 0.1761

1.6000 0.2041

1.7000 0.2304

1.8000 0.2553

1.9000 0.2788

2.0000 0.3010

QUIT/DONE

You might also like