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

Chapter 2 MATLAB

The document contains examples of MATLAB code for performing various operations on matrices and vectors including creating, modifying, and combining matrices of different sizes and values. Multiple matrices and vectors are defined with a variety of elements and dimensions for testing functions.

Uploaded by

hariss123a63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Chapter 2 MATLAB

The document contains examples of MATLAB code for performing various operations on matrices and vectors including creating, modifying, and combining matrices of different sizes and values. Multiple matrices and vectors are defined with a variety of elements and dimensions for testing functions.

Uploaded by

hariss123a63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

% CHAPTER 02

% Question 01:
r=[3 4*2.55 68/16 45 (110)^(1/3) cos(25) 0.05]

r =

3.0000 10.2000 4.2500 45.0000 4.7914 0.9912 0.0500

%Question 02:
o=[54/(3+(4.2)^2) 32 (6.3)^2-(7.2)^2 54 exp(3.7) sin(66)+cos((3*pi)/8)]

o =

2.6163 32.0000 -12.1500 54.0000 40.4473 0.3561

% Question 03:
q=[25.5; (14*tan(58))/((2.1)^2+11); factorial(6); (2.7)^4; 0.0375; pi/5]

q =

25.5000
7.5686
720.0000
53.1441
0.0375
0.6283

% Question 04:
y=[32/(3.2)^2; (sin(35))^2; 6.1; 2*log(29); 0.00552; (log(29))^2; 133]

y =

3.1250
0.1833
6.1000
6.7346
0.0055
11.3387
133.0000

% Question 05:
x=0.85;
y=12.5;
p=[y; y^x; log(y/x); y*x; x+y]

p =

12.5000
8.5580
2.6882

1
10.6250
13.3500

% Question 07:
t=[2:5:37]

t =

2 7 12 17 22 27 32 37

% Question 08:
w=linspace(81,12,9)

w =

81.0000 72.3750 63.7500 55.1250 46.5000 37.8750 29.2500 20.6250 12.0000

% Question 10:
u=linspace(-21,12,15)'

u =

-21.0000
-18.6429
-16.2857
-13.9286
-11.5714
-9.2143
-6.8571
-4.5000
-2.1429
0.2143
2.5714
4.9286
7.2857
9.6429
12.0000

% Question 17:
B(:,1)=linspace(1,5,5);
C(:,1)=linspace(0,0,5);
D(:,1)=linspace(3,3,5);
VEC=[B C D]

VEC =

1 0 3
2 0 3
3 0 3
4 0 3

2
5 0 3

% Question 37:
%part(a):
a=ones(2)

a =

1 1
1 1

b=zeros(2)

b =

0 0
0 0

c=[a; b]

c =

1 1
1 1
0 0
0 0

%part(b):
d=eye(3)

d =

1 0 0
0 1 0
0 0 1

ei=ones(3)

ei =

1 1 1
1 1 1
1 1 1

gg=[d, ei]

gg =

1 0 0 1 1 1

3
0 1 0 1 1 1
0 0 1 1 1 1

%part(c):
h=ones(2,4)

h =

1 1 1 1
1 1 1 1

i=zeros(1,4)

i =

0 0 0 0

j=ones(1,4)

j =

1 1 1 1

mat=[h; i; j]

mat =

1 1 1 1
1 1 1 1
0 0 0 0
1 1 1 1

% Question 40:
A=ones(2)

A =

1 1
1 1

A(3,:)=zeros(1,2)

A =

1 1
1 1
0 0

A(4,:)=zeros(1,2)

4
A =

1 1
1 1
0 0
0 0

A(:,3)=zeros(4,1)

A =

1 1 0
1 1 0
0 0 0
0 0 0

A(:,4)=zeros(4,1)

A =

1 1 0 0
1 1 0 0
0 0 0 0
0 0 0 0

A(:,5:8)=zeros(4)

A =

1 1 0 0 0 0 0 0
1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0

A(3:4,3:4)=1

A =

1 1 0 0 0 0 0 0
1 1 0 0 0 0 0 0
0 0 1 1 0 0 0 0
0 0 1 1 0 0 0 0

A(1:2,5:6)=1

A =

1 1 0 0 1 1 0 0
1 1 0 0 1 1 0 0
0 0 1 1 0 0 0 0

5
0 0 1 1 0 0 0 0

A(3:4,7:8)=1

A =

1 1 0 0 1 1 0 0
1 1 0 0 1 1 0 0
0 0 1 1 0 0 1 1
0 0 1 1 0 0 1 1

You might also like