Chapter3

Click here to see book problems

Problem 1
Script file:

%problem 1

disp(‘problem 1’)

x= 0:7;

y= (x.^2-(x./(x+3)))

2. For the function y = x^(4)e^(-x), calculate the value of y for the following values of
x using element-by-element operations: 1.5, 2, 2.5, 3, 3.5, 4.



Problem 2
Script file:

%problem 2
disp(‘problem 2’)
x=[1.5:0.5:4];
y=x.^4.*exp(-x);
3. For the function y = (x+x\sqrt(x+3))(1+2x^(2))-x^(3), calculate the value of y for the following values
of x using element-by-element operations: -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2.

Problem 3
Script file:

%problem 3
disp(‘problem 3’)
x=[-2:0.5:2];
y = (x+x.*sqrt(x+3)).*(1+2*x.^2)-x.^3;
Problem 4
Script file:

%problem 4
disp(‘problem 4’)
x=[15:10:65];
y= (4*sind(x)+6)./((cos(x)).^2+sind(x)).^2;
Problem 5
Script file:

%problem 5
disp(‘problem 5’)
V=[4000:500:1000];
r=nthroot(((3*V)/(4*pi)),3);
S=4*pi*r.^2;
vector=[r;V;S];
Problem 6
Script file:

%problem 6 a
disp(‘problem 6 a’)
u = 0.35;
T = [5:5:35];
F= (70*u)./(u*sind(T)+cosd(T));
%problem 6 b
disp(‘problem 6b’)
u = 0.35;
T = [5:0.01:35];
F= (70*u)./(u*sind(T)+cosd(T));
minV= min(F);
maxV= max(F);
Problem 7
Script file:

%problem 7
format long g;
L=100000;
r=0.06;
x=[0:5:30];
n=30;
B=(L*((1+r./12).^(12*n)-(1+r./12).^(12*x)))/((1+r./12.)^(12*n)-1);
table= [x; B];
Problem 8
Script file:

%problem 8
x=-5.6; y=11; z=-14;
vectorU=[x y z];
lenghtU=sqrt(sum(vectorU.^2));
Problem 9
Script file:

%problem 9
u=[4 13 -7];
Lu=sqrt(sum(u.^2));
un=u./Lu;
Problem 10
Script file:

%problem 10
uOne=[3.2 -6.8 9];
uTwo=[-4 2 7];
LuTwo=sqrt(sum(uTwo.^2));
LuOne=sqrt(sum(uOne.^2));
anglevOT=acosd((sum(uOne.*uTwo))/(LuOne*LuTwo));
Problem 11
Script file:

%problem 11
d=[2 4 3];
a=d+d;
b=d^d;
c=d*d;
de=d^2;
Problem 12
Script file:

%problem 12
v=[3 -1 2];
u=[6 4 -3];
a=v^u;
b=v^u;
c=v*u’;
Problem 13
Script file:

%problem 13
v=[1 3 5 7];
a=v*3;
b=v^2;
c=v^0;
Problem 14
Script file:

%problem 14
v=[5 4 3 2];
a=(v*2)^(-1);
b=v^v;
c=v/sqrt(v);
de=(v^2)/(v^v);
Problem 15
Script file:

%problem 15
x=[0.5, 1, 1.5, 2, 2.5];
y=[0.8, 1.6, 2.4, 3.2, 4.0];
az= x.^2+2*(x.*y);
bz=x.*y*exp(y./x)-nthroot(((x.^4)*(y.^3)+8.5),3);
Problem 16
Script file:

%problem 16
r=1.6*10^3;
s=14.2;
t=[1, 2, 3, 4, 5];
x=[2, 4, 6, 8, 10];
y=[3, 6, 9, 12, 15];
G=x.*t+(r/s^2)*(y.^2-x)*t;
R=((r*(-x.*t+y.*t^2))/15)-(s^2)*(y-0.5*x.^2)*t;
Problem 17
Script file:

%problem 17
roa=[8 5 -4]; rob=[-7 9 6]; roc=[-5 -2 11];
rab=roa+rob;
rac=roa+roc;
area=(rab.*rac)/2;
Problem 20
Script file:

%problem 20
a=[7 -4 6]; b=[-4 7 5]; c=[5 -6 8];
lhs=a*(b*c);
rhs=b*(a.*c)-c*(a.*b);
Problem 29
Script file:

fprintf(‘Problem 29’)
A =[2 1 4; 4 1 8; 2 -1 3];
B = [3 2 -1; 6 8 -7; 4 4 0];
C = [-9 8 3; 1 7 -5; 3 3 6];
x1 = A + B
x2 = B + A
x3 = A.*(B.*C)
x4 = (A.*B).*C
x5 = (A.*B).*C
x6 = 5.*(B+C)
x7= 5.*B + 5.*C
x8 = (A+B).*C
x9 = A.*C + B.*C



Problem 30
Script file:

% PROBLEM 30 (^t means transpose)
fprintf(‘problem 30’)
fprintf(‘A*B does not equal B*A’)
LHS = A.*B
RHS = B.*A

fprintf(‘Does (B*A)^-1 = B^-1*c^-1? NO ‘)
LHS = inv(B.*C)
RHS = inv(B) .* inv(C)

fprintf(‘Does (A^-1)^t = (A^t)^-1 ? YES ‘)
LHS = [inv(A)]’
RHS = inv(A’)

fprintf(‘Does (A+B)^t = A^t + B^t ? YES’)
LHS = (A + B)’
RHS = A’ + B’



Problem 31
Script file:

%problem 31
fprintf(‘problem 31’)
A = randi(5,3);
a = A.^A
b = A.*A
c = A*A – 1
d = A./A
e = det(A)
f = inv(A)



Problem 32
Script file:

%problem 32
fprintf(‘Problem 32’)
M = magic(5)
fprintf(‘The sum of each row as a colum vector is: ‘)
x = sum(M)’
fprintf(‘diagonal sum is : ‘)
diagonalsum = sum(diag(M))
sumC1=sum(M(:,1))%sumC1 is the sum of all elements in colum 1
sumC2=sum(M(:,2))
sumC3=sum(M(:,3))
sumC4=sum(M(:,4))
sumC5=sum(M(:,5))



Problem 33
Script file:

%problem 33
%setting A with values of x, y and z of each eqn separated with semicolon
A = [-2 5 7 ; 3 -6 2 ;9 -3 8];
B = [-17.5 ; 40.6 ; 56.2];
%solving by using left division: X = A\B p.71
fprintf(‘problem 33’)
X = A\B
%also solving by using the inverse of A: X=A^-1*B
%or use Xb=inve(A)*B



Problem 34
Script file:

%problem 34
A = [ 2 -4 5 -3.5 1.8 4 ; -1.5 3 4 -1 -2 5 ; 5 1 -6 3 -2 2 ; 1.2 -2 3 4 -1 4 ; 4 1 -2 -3 -4 1.5 ; 3 1 -1 4 -2 -4 ];
B = [ 52.52 ; -21.1 ; -27.6 ; 9.16 ; -17.9 ; -16.2 ];
fprintf(‘problem 34’)
X = A\B



Problem 35
Script file:

%problem 35
fprintf(‘Problem 35’)
A = [25 40 60 70 32 0; 0 1 -1 0 0 0;0 1 0 1 -10 0; -1 1 1 0 0 0; 1 0 1 0 -4 -4;1 1 1 1 1 1];
B = [4897000; 11000; 0; 0; 0; 100000];
x = A\B;
numStudents = x(1)
numAlumni = x(2)
numFaculty = x(3)
numPublic = x(4)
numVeterans = x(5)
numGuests = x(6)



Problem 36
Script file:

%problem 36
fprintf(‘Problem 36’)
mix1 = [3 1 1 2 1]
mix2 = [1 2 1 3 1];
mix3 = [1 1 0 3 3];
mix4 = [2 0 3 1 2];
mix5 = [1 2 3 0 2];
mixAvailable = [105 74 102 118 121 ];
numPanckagesMix1 = min(mixAvailable./mix1)
numPanckagesMix2 = min(mixAvailable./mix2)
numPanckagesMix3 = round(min(mixAvailable./mix3))
numPanckagesMix4 = min(mixAvailable./mix4)
numPanckagesMix5 = min(mixAvailable./mix5)



Problem 37
Script file:

%problem 37
fprintf(‘Problem 37’)
V1 = 28; V2 = 36; V3 = 42;
R1 = 16; R2 = 10; R3 = 6;
R4 = 12; R5 = 8; R6 = 16;
R7 = 4; R8 = 5;
A = [-(R1 + R2 + R3) R2 R3 0; R2 -(R2 + R4 + R5 + R7) R4 R7; R3 R4 -(R3 + R4 + R6) R6; 0 R7 R6 -(R6 + R7 + R8)];
B = [-V1; 0; V2; -V3];
I = A\B;
i1 = I(1,1)
i2 = I(2,1)
i3 = I(3,1)
i4 = I(4,1)