Chapter 2 Matlab
Chapter 2 Matlab
% Question 01:
r=[3 4*2.55 68/16 45 (110)^(1/3) cos(25) 0.05]
r =
%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 =
% 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 =
% 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