ENGR133, Problem Set-02
Authored by: Garrett Koester
Authored on: 7/8/2023
Problem #2.13
Initialize Variables
clear, clc, close all
A=[9 6;2 7];
B=[8 9;6 2];
Find the sum of A and B
sum=A+B % A and B are added together
sum = 2×2
17 15
8 9
Find the array product w=A*B
prAB=A*B % A and B are multiplied
prAB = 2×2
108 93
58 32
Find the array product z=B*A
prBA=B*A % B and A are multiplied
prBA = 2×2
90 111
58 50
Is z=w?
% No, z and w are not the same
Problem #2.16
Initialize Variables
clear, clc, close all
A=[5 9;6 2];
B=[4 7;2 8];
Find the array quotient C=A/B
rC=rem(A,B); % Reminder matrix of C
1
qC=(A-rC)/B % Quotient matrix of C as quotient = (dividend - reminder)/
divisor
qC = 2×2
1.0000 0
2.6667 -2.3333
Find the array quotient D=B/A
rD=rem(B,A); % Reminder matrix of D
qD=(B-rD)/A % Quotient matrix of D as quotient = (dividend - reminder)/
divisor
qD = 2×2
0 0
1.0909 -0.9091
Find the array quotient E=A\B
rE=rem(B,A); % Reminder matrix of E
qE=(B-rE)/A % Quotient matrix of E as quotient = (dividend - reminder)/
divisor
qE = 2×2
0 0
1.0909 -0.9091
Find the array quotient F=B\A
rF=rem(A,B); % Reminder matrix of F
qF=(A-rF)/B % Quotient matrix of F as quotient = (dividend - reminder)/
divisor
qF = 2×2
1.0000 0
2.6667 -2.3333
Are any of C, D, E, or F equal?
% Yes, quotient matrices C & F are equal, as are quotient matrices D & E.
Problem #2.19
Problem Statement
Plot the following function for x over the interval
Initialize Variables
clear, clc, close all
x=[-2:0.1:16]; % defining the range of x with step increment of 0.1
y=(4.* cos(x)) ./ (x+exp(-0.75.*x)); % y is substituted for f(x)
2
Plotting the Function
plot(x,y) % Create plot with grid
title ('Plotting the Curve for Problem #2.19')
xlabel('x'); % Horizontal axis label
ylabel('f(x)'); % Vertical axis label
Problem #2.26
Problem Statement
Two divers start at the surface and establish the following coordinate system: x is to the west, y is to the north,
and z is down. Diver 1 swims 100 ft east, then 30 ft south, and then dives 40 ft. At the same time, diver 2 dives
30 ft, swims east 40 ft, and then south 60 ft.
clear, clc, close all
Initialize Variables
x1=100; % Diver 1 swims 100 ft east
y1=30; % Diver 1 swims 30 ft south
z1=40; % Diver 1 dives 40 ft
x2=40; % Diver 2 swims 40 ft east
y2=60; % Diver 2 swims 60 ft south
z2=30; % Diver 2 dives 30 ft
3
Part 1: Compute the distance between diver 1 and the starting point.
ans1=sqrt(x1^2+y1^2+z1^2);
disp('Part 1');
Part 1
disp('Distance between diver 1 and starting point');
Distance between diver 1 and starting point
disp(ans1);
111.8034
Part 2: How far in each direction must diver 1 swim to reach diver 2?
x=abs(x1-x2);
y=abs(y1-y2);
z=abs(z1-z2);
disp('Part 2');
Part 2
disp('East : ');
East :
disp(x);
60
disp('South :');
South :
disp(x);
60
disp('Depth : ');
Depth :
disp(x);
60
Part 3: How far in a straight line must diver 1 swim to reach diver 2?
dist=sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2);
disp('Part 3');
4
Part 3
disp('Diver 1 should swim this much to diver 2 : ');
Diver 1 should swim this much to diver 2 :
disp(dist);
67.8233
Problem 2.30
Problem Statement
A water tank consists of a cylindrical part of radius r and height h, and a hemispherical top. The tank is to be
constructed to hold 500 of fluid when filled. The surface area of the cylindrical part is 2 , and its volume is
. The surface area of the hemispherical top is given by . The cost to construct the cylindrical part of
the tank is $300/ of surface area; the hemispherical part costs $400/ . Plot the cost versus r for ,
and determine the radius that results in the cost. Compute the corresponding height h.
clear, clc, close all
Initialize Variables
V=500; % Volume of tank (m^3)
cost_cylinder=250; % Cost of the cylindrical part (RM/m^2)
cost_hemisphere=350; % Cost of the hemispherical part (RM/m^2)
r=2:0.1:10; % Radius values (2 to 10 with a step of 0.1)
h=V ./ (pi .* r.^2); % Height corresponding to each radius
Surface Areas
A_cylinder = 2*pi*r.*h; % Surface area of the cylindrical part
A_hemisphere = 2*pi*r.^2; % Surface area of the hemispherical part
Costs
cost=cost_cylinder*A_cylinder+cost_hemisphere*A_hemisphere; % Total cost
Plotting the cost versus radius
plot(r,cost, 'b', 'LineWidth', 2);
xlabel('Radius (m)');
ylabel('Cost (RM)');
title ('Cost vs. Radius');
grid on;
5
Finding the radius that results in the least cost
[min_cost, idx] =min(cost);
optimal_radius=r(idx);
optimal_height=h(idx);
Results
fprintf('Radius that results in the least cost: %.2f m\n', optimal_radius);
Radius that results in the least cost: 3.80 m
fprintf('Corresponding height: %.2f m\n', optimal_height);
Corresponding height: 11.02 m
6