Chapter2

Click here to see book problems

Problem 1
Script file:

%problem 1
disp(‘problem 1 row vector a’)
a = [9 1 3^2 7/4 0 2.25*8.5 0.8 sin(pi/8)];
Problem 2
Script file:

%problem 2
disp(‘problem 2 row vector b’)
b = [sqrt(5.2^3) (6.71*(10^3)) (3+5.1^2)*cosd(53) 15.8 nthroot(90,3) (sin(pi/3)/tand(20))];
Problem 3
Script file:

%problem 3
disp(‘problem 3 colum vector c’)
c = [2.1*10^-2; sin(1.7*pi); 28.5; (2.7)^(4/3); exp(3)];
Problem 4
Script file:

%problem 4
disp(‘problem 4 colum vector d’)
d = [0.75*5.2^0.7; 11.1; nthroot(60,3); tan((10*pi)/11); (cosd(5))^2; 0.116];
Problem 5
Script file:

%problem 5
disp(‘problem 5 row vector e’)
x=3.4; y=5.8;
e = [x/y x+y x*y y^2 x];
Problem 6
Script file:

%problem 6. semicolon gives the colums
disp(‘problem 6 colum vector f’)
c=4.5; d=2.8;
f= [d^2; c; (c+d); c^d; d];
Problem 7
Script file:

%problem 7, [fisrt element:spacing:last element]
disp(‘problem 7 row vector g’)
g = [3:4:27];
Problem 8
Script file:

%problem 8, linspace command do: variablename=linspace(first element, last
%elelmet, number of elelments)
disp(‘problem 8 row vector h’)
h = linspace(68,12,8);
Problem 9
Script file:

%problem 9 to conver row to colum use one cotation mark at the end ]’
disp(‘problem 9 colum vector M’)
M = [6.4: 0.8: 12]’;
Problem 10
Script file:

%problem 10
disp(‘problem 10. culum vector N’)
N= linspace(44, 23, 7)’;
Problem 11
Script file:

%problem 11. row vector using colon symbol.
% fisrt element, spacing, last elelmeet
disp(‘problem 11 variable Time’)
Time = 0 : 1 : 20;
Problem 12
Script file:

%problem 12. row vector with linspace command
%first element, last elemet, number of elelments
disp(‘problem 12 variable Fours’)
Fours = linspace( 4, 4, 9);
Problem 13
Script file:

%problem 13. Using the colon symbol,
%create a variable named Sevens that is a row vector
%of seven elements that are all the number 7.
disp(‘problem 13 variable Sevens’)
Sevens(1:7) = 7;
Problem 14
Script file:

%problem 14
%Use a single command to create a row vector (assign it to a variable named
%P) with eight elements such that the last element is 5.9 and the rest of the elements
%are 0s. Do not type the vector elements explicitly. P.57
disp(‘problem 14 variable P’)
P(8) = 5.9;
Problem 15
Script file:

%problem 15
%Use a single command to create a row vector (assign it to a variable named
%q) with nine elements such that the last four elements are 8.1 and the rest of
%the elements are 0s. Do not type the vector elements explicitly
disp(‘problem 15cvariable q’)
q(6:9) = 8.1;
Problem 16
Script file:

%problem 16
disp(‘problem 16 row vector R’)
Problem 17
Script file:

%problem 17
disp(‘problem 17’)
v=41:-3:29; w=17:4:37;
u=[v w];
Problem 18
Script file:

%problem 18
disp(‘problem 18’)
T = [5:5:25]’;
S = [25:2:33]’;
R = [ T; S];
Problem 19
Script file:

%problem 19 a
disp(‘problem 19 a’)
A = [4:3:13];
B = [14:-2:6]’;
C = [B’ A];
%problem 19 b
disp(‘problem 19 b’)
A = [4:3:13];
B = [14:-2:6]’;
D = [A:B]’;
Problem 20
Script file:

%problem 20
disp(‘problem 20’)
vA = [1:3:34];
vB=[vA(1:5) vA(9:12)];
Problem 24
Script file:

%problem 24
a = [1.0000:1:7.0000];
b = [7:-1:1];
c = linspace(2,9,7);
A = [a;b;c]
Problem 25
Script file:

%problem 25
a = linspace(4,4,5);
b = linspace(5,5,4);
B = [a b]
Problem 26
Script file:

%problem 26
C = [6:2:8;6:2:8;6:2:8;6:2:8;6:2:8]
Problem 27
Script file:

%problem 27
D = [ linspace(1,1,4);linspace(1,1,4);linspace(1,1,4); 8:-2:2]
Problem 28
Script file:

%problem 28
E = [zeros(3,4) [8:-1:6]’]
Problem 29
Script file:

%problem 29
F = [zeros(2,6);zeros(1,2) [8:-2:2] ]
Problem 30
Script file:

%problem 30
G= [ones(3,5); zeros(3,3) ones(3,2)]
Problem 37
Script file:

%ptoblem 37
M = [linspace(1,25,5); linspace(3,27,5);linspace(5,29,5)];
Va = M(3,:)
Vb = M(:,4)
Vc = [M(2,:) [M(:,3)]’]
Problem 38
Script file:

%problem 38
%N = [linspace(0,15,6); linspace(18,33,6); linspace(36,51,6)];
N = reshape(0:3:51,6,3)’;
Ua = [N(1,1:3) N(3,4:6)]
Ub = [N(:,1);N(:,3)]
Uc = [ N(2,2:5) [N(2:3,5)]’]’
Problem 39
Script file:

%problem 39
G = [linspace(0.1,0.7,7); linspace(10,4,7); linspace(0,1.2,7); linspace(5,-7,7)];
Ma = [[G(1,1:2), G(1,6:7)]; [G(3,1:2),G(3,6:7)];[G(4,1:2),G(4,6:7)]]
Problem 40
Script file:

%problem 40
K = [linspace(.25,1.75,7);linspace(2,14,7);linspace(25,55,7)];
Ga = [K(:,2)’, K(:,5)’;K(2,1:6);K(3,2:7)]
Problem 44
Script file:

%probem 44
a = [eye(3),eye(3)];
b = [zeros(2,3), ones(2,2)];
c = [ones(3,1),zeros(3,2),[eye(1);zeros(2,1)]];
Problem 45
Script file:

%problme 45
A = eye(2)
B = ones(1,2)
C = zeros(3,3)