Solved Workbook 2
Solved Workbook 2
ANSWER:
The answer is 0.444444.
ANSWER:
The answer is 0.013889.
ANSWER:
The answer is 1.038462.
ANSWER:
eggs_remain = 5
ANSWER:
Case #1:
LHS =1.6428
RHS =1.6428
Case #2:
LHS = 1.0110
RHS =1.0110
ANSWER:
LHS = -30.1634
RHS = -30.1634
LHS =-1.3304e+05
RHS = -1.3304e+05
LAB SESSION #2:
ANSWER:
The estimated age of the footprint is approximately -2112 years.
clear,clc
c=300*exp(6); % Speed of light in m/s
wavelength_p=530*exp(-9); % Green wavelength in meters
wavelength_s=630*exp(-9); % Red wavelength in meters
v = c * ((wavelength_p / wavelength_s)^2 - 1) / ((wavelength_p / wavelength_s)^2 +
1)
ANSWER:
v = -2.0713e+04
ANSWER:
q = 1.1838e+08
ANSWER:
part (a)
alpha = 26.9669
beta = 46.2365
gamma = 106.7966
Total = 180
part (b)
LHS = 0.1400
RHS = -0.1400
clear,clc
%PART(a)
anine=ones(1,9)*9
%PART(b)
MA=ones(4,3)*12
%PART(c)
E=[zeros(1,5);zeros(1,2),3:5;zeros(1,2),4:6;zeros(1,2),7:9]
ANSWERS:
anine =
9 9 9 9 9 9 9 9 9
MA =
12 12 12
12 12 12
12 12 12
12 12 12
E=
0 0 0 0 0
0 0 3 4 5
0 0 4 5 6
0 0 7 8 9
%Magnitude of F1
F1 = 600;
theta_1 = 4/5; % Angle of F1 with respect to the positive x-axis
theta_2=0; % Angle f=of F1 with respect to the positive y-axis
theta_3= 3/5; %Angle of F1 with respect to the positive z-axis
% Magnitude of F2
F2 = 400;
theta_4 =60; %Angle of F2 with respect to the positive x-axis
theta_5=45; %Angle of F2 with respect to the positive y-axis
theta_6=120; %Angle of F2 with respect to the positive z-axis
%Components of F1
F1x = F1 * (theta_1);
F1y = F1 * (theta_2);
F1z= F1*(theta_3);
%Components of F2
F2x = F2 * cosd(theta_4);
F2y = F2 * cosd(theta_5);
F2z=F2*cosd(theta_6);
%Adding x,y and z components
Fx = F1x + F2x;
Fy = F1y + F2y;
Fz= F1z+F2z;
%Resultant force
F = sqrt(Fx^2 + Fy^2+Fz^2);
disp(['Magnitude of the resultant force: ', num2str(F)]);
ANSWER:
Magnitude of the resultant force: 753.6577
%Magnitude of F1
F1=750;
F1x=750*cosd(45)*cosd(30);
F1y=750*cosd(45)*sind(30);
F1z=-750*sind(45);
%Magnitude of resultant Force
%Fr=(300i+650j+250k)
Frx=300;
Fry=650;
Frz=250;
%Calculation of F
%Frx+Fry+Frz=F1x+F1y+F1z+Fx+Fy+Fz;
Fx=Frx-F1x;
Fy=Fry-F1y;
Fz=Frz-F1z;
%Magnitude of F
F=sqrt(Fx^2+Fy^2+Fz^2);
%Calculation of Angles
alpha=acosd(Fx/F);
beta=acosd(Fy/F);
gamma=acosd(Fz/F);
disp(['Magnitude of F: ',num2str(F)])
disp(['Alpha angle is: ' num2str(alpha)])
disp(['beta angle is: ' num2str(beta)])
disp(['gamma angle is: ' num2str(gamma)])
ANSWERS:
Magnitude of F: 884.5241
Alpha angle is: 100.374
beta angle is: 64.2099
gamma angle is: 28.0907
% Input parameters
force = [-120; -90; -80]; % Force vector in lb
length_cable = 34; % Length of the cable in ft
ANSWERS:
Height of the pole (z-coordinate): -16 ft
clear,clc;
O=[0 0 0];
A=[3 3 -2]; F1=[-20 10 30];
r_OA=A-O;
M=cross(r_OA,F1);
Magnitude_M=sqrt(sum(M.^2));
fprintf('The Magnitude Of Moment ''M'' Produced By The Force''F'' About Point
''O'' Is %.4f kN-m.\n',Magnitude_M)
ANSWERS:
The Magnitude Of Moment 'M' Produced By The Force'F' About Point 'O' Is
150.6652 kN-m.
clear,clc;
clc,clear
m=[0.5 0.8 0.2 1.1 0.4 0.9];
x=[-10 -18 -7 5 0 25];
y=[8 6 11 12 -8 -20];
z=[32 19 2 -9 -6 8];
Mx=sum(m.*x)
My=sum(m.*y)
Mz=sum(m.*z)
M=sum(m)
X=Mx/M
Y=My/M
Z=Mz/M
disp([X Y Z])
ANSWERS:
Mx = 7.2000
My = 3.0000
Mz = 26.5000
M = 3.9000
X = 1.8462
Y = 0.7692
Z = 6.7949
1.8462 0.7692 6.7949
Clear,clc:
% Given values
V1 = 12; V2 = 24; V3 = 40;
R1 = 20; R2 = 12; R3 = 8;
R4 = 6; R5 = 6; R6 = 10;
% Construct the coefficient matrix A
A = [-(R1 + R2), R2, 0; R2, -(R2 + R3 + R4), 0; 0, R4 + R5 + R6, -(R4 + R5 +
R6)];
% Construct the right-hand side vector B
B = [-V1; V2; -V3];
% Solve for the mesh currents using the inverse of A
X = A \ B;
% Extract the mesh currents
I1 = X(1);
I2 = X(2);
I3 = X(3);
% Display the results
fprintf('Mesh Current I1: %.2f A\n', I1);
fprintf('Mesh Current I2: %.2f A\n', I2);
fprintf('Mesh Current I3: %.2f A\n', I3);
ANSWERS:
Mesh Current I1: 0.03 A
Mesh Current I2: -0.91 A
Mesh Current I3: 0.91 A
clear,clc;
Running_Speed=8.6;
Swimming_Speed=3.9;
x=[0:5000];
Time=((10000-x)/Running_Speed)+(sqrt(x.^2+3000^2)/Swimming_Speed);
[Minimum_Time Position]=min(Time)
fprintf('The Minimum Distance That Can Be Covered The Person To Reach the
Drowning Child Is %.4f ft.\n',x(Position))
Answer:
Minimum_Time = 1.8484e+03
Position = 1527
The Minimum Distance That Can Be Covered The Person To Reach the Drowning
Child Is 1526.0000 ft.
Answer:
AAmin =
844.1299
i=
273
amin =
37.2000
hmin =
32.2581
Answer:
n t
1.0000 0.6386
2.0000 0.5428
3.0000 0.4614
4.0000 0.3922
5.0000 0.3333
6.0000 0.2833
7.0000 0.2408
8.0000 0.2047
t = 0:0.01:4; % Specify the range of values for t
% Calculate displacement and velocity
x= 4.219 * (exp(-1.58*t) - exp(-6.32*t));
v= 26.67 * exp(-6.32*t) - 6.67 * exp(-1.58*t);
% Plot displacement
subplot(2,1,1)
plot(t,x,'r')
title('Displacement vs Time');
xlabel('Time (s)');
ylabel('Displacement (m)');
% Plot velocity
subplot(2,1,2);
plot(t, v, 'k');
title('Velocity vs Time');
xlabel('Time (s)');
ylabel('Velocity (m/s)');
ANSWER:
P=0:0.01:200; % population in thousands
Q=(1020.*sqrt(P)).*(1-(0.01.*(sqrt(P))));% Water demand
% plot
plot(P,Q,'r')
title('Population vs Water demand')
xlabel('Population(in thousands)')
ylabel('Water demand(in gallons/min)')
ANSWER:
clc,clear
for k=1:3
a=input('enter value of a:');
b=input('enter value of b:');
c=input('enter value of c:');
D=b^2-4*a*c;
if D<0
fprintf('the equation has no roots. \n\n')
elseif D==0
root=-b/(2*a);
fprintf('\n the equation has one root: \n')
fprintf('%.3f \n\n',root)
else
root1=(b+sqrt(D))/(2*a);
root2=(-b-sqrt(D))/(2*a);
fprintf('\n the equation has two root: \n')
fprintf('%.3f and %.3f \n\n',root1,root2)
end
end
ANSWER:
enter value of a:2
enter value of b:8
enter value of c:8
the equation has one root: -2.000
enter value of a:-5
enter value of b:3
enter value of c:4
the equation has two root: -0.643 and 1.243
enter value of a:-2
enter value of b:7
enter value of c:4
the equation has two root: -0.500 and 4.000
clear,clc
gender=input('enter your gender (male or female):','s')
age=input('please enter your age:')
RHR=input('please enter your resting heart rate:')
fit=input('please enter your fitness level (low, medium,high):','s')
gender=lower(gender)
fit=lower(fit)
switch fit
case 'low'
INTEN=0.55
case 'high'
INTEN=0.65
case 'high'
INTEN=0.8
end
switch gender
case 'male'
THR=((220-age)-(rjr)*INTEN+rjr);
case 'female'
THR=((206-0.88*age)-(rjr)*INTEN+rjr);
end
fprintf('\n The recommended training heart rate is %.0f\n\n',THR)
ANSWER:
enter your gender (male or female):male
please enter your age:21
please enter your resting
heart rate:62
please enter your fitness level (low, medium,high):low
The recommended training heart rate is 137
enter your gender (male or female):female
please enter your age:19
please enter your resting
heart rate:67
please enter your fitness
level (low, medium,high):high
The recommended training heart rate is 146
clear,clc
for j=1:2
w=input('please enter your weight in lb :');
a=input('please enter your height in ft :');
b=input('please enter your height in inches:');
h=(a*39)+b;
BMI=703*w/(h^2);
if BMI<18
fprintf('\n your BMI value is %.1f,which classifies you as
underweight\n\n',BMI)
elseif BMI<25
fprintf('\n your BMI value is %.1f,which classifies you as normal\n\n',BMI)
elseif BMI<30
fprintf('\n your BMI value is %.1f,which classifies you as
overweight\n\n',BMI)
else
fprintf('\n your BMI value is %.1f,which classifies you as obese\n\n',BMI)
end
end
ANSWER:
please enter your weight in lb :180
please enter your height in ft :6
please enter your height in
inches:2
your BMI value is 2.3,which classifies you as underweight
please enter your weight in lb :150
please enter your height in ft :5
please enter your height in
inches:1
your BMI value is 2.7,which classifies you as underweight
clc,clear
for j=1:3
n(1:8)=0;
cost=randi([1
5000],1,1)/100;
fprintf('the total charge%.2f\n',cost)
pay=input('please enter payment (1,5,10,20 or 50):');
if pay<cost
fprintf('insufficient payment\n\n')
continue
else
change=pay-cost;
if change>=20
n(1)=1;
change=change-20;
end
if change>=10
n(2)=1;
change=change-10;
end
if change>=5
n(3)=1;
change=change-5;
end
while change>=1
n(4)=n(4)+1;
change=change-1;
end
while change>=0.25
n(5)=n(5)+1;
change=change
0.25;
end
while change>=0.10
n(6)=n(6)+1;
change=change
0.10;
end
if change>=0.05
n(7)=1;
change=change
0.05;
end
change=change+0.000001
while change>=0.01
n(8)=n(8)+1;
change=change-0.01;
end
end
fprintf('\t$20\t\t$10\t\t$5\t\t$1\t$0.25\t$0.10\t$0.05\t$0.01\n')
fprintf('\t%i\t',n)
fprintf('\n\n')
end
ANSWER:
the total charge 47.52
please enter payment (1,5,10,20 or 50):50
change = 0.0300
$20 $10 $5
$1 $0.25 $0.10
$0.05 $0.01
0 0 0
2 1 2
0 3
change = 0.0200
$20 $10 $5
$1 $0.25 $0.10
$0.05 $0.01
1 1 1
13 1 0
0 2
clear,clc
for j=1:3
p=input('please enter te pressure value:');
old=input('please enter the old unit (Pa,psi,atm,torr):','s');
new=input('please enter the new desired unit(Pa,psi,atm,torr):','s');
switch old
case 'Pa'
temp=p;
case 'psi'
temp=6.894757e03*p;
case 'atm'
temp=1.01325e05*p;
case 'torr'
temp=1.333224e02*p;
end
switch new
case 'Pa'
pnew=temp;
case 'psi'
pnew=temp/6.894757e03;
case 'atm'
pnew=temp/1.01325e05;
case 'torr'
pnew=temp/1.333224e02;
end
fprintf('the converted pressure is %.1f %s \n\n',pnew,new)
end
ANSWER:
please enter te pressure value:70
please enter the old unit (Pa,psi,atm,torr):psi
please enter the new desired unit(Pa,psi,atm,torr):Pa
the converted pressure is 482633.0 Pa
please enter te pressure value:120
please enter the old unit (Pa,psi,atm,torr):torr
please enter the new desired unit(Pa,psi,atm,torr):atm
the converted pressure is 0.2 atm
please enter te pressure value:8000
please enter the old unit (Pa,psi,atm,torr):Pa
please enter the new desired unit(Pa,psi,atm,torr):psi
the converted pressure is 1.2 psi
clc,clear
for j=1:3
x=input('enter the time of the day(day,evening,night):','s');
t=input('enter the time duration in minutes:');
switch x
case 'day'
if t<10
cost=t*0.10;
elseif t>=10 & t<30
cost=((t-10)*0.08)+1;
else
cost=((t-30)*0.06)+2.60;
end
case 'evening'
if t<10
cost=t*0.07;
elseif t>=10 & t<30
cost=((t-10)*0.05)+0.70;
else
cost=((t-30)*0.04)+1.70;
end
case 'night'
if t<10
cost=t*0.04;
elseif t>=10 & t<30
cost=((t-10)*0.03)+0.40;
else
cost=((t-30)*0.02)+1;
end
end
fprintf('the cost of telephone call is : %.1f \n\n',cost)
end
ANSWER:
enter the time of the day(day,evening,night):day
enter the time duration in minutes:8.3
the cost of telephone call is : 0.8
enter the time of the day(day,evening,night):evening
enter the time duration in minutes:34.5 the cost of telephone call is : 1.9
enter the time of the day(day,evening,night):night
enter the time duration in minutes:29.6 the cost of telephone call is : 1.0
clc,clear
v = [5 17 -3 8 0 -7 12 15 20 -6 6 4 -7 16];
for a = 1 : length(v)
if v(a)>0 & (rem(v(a),3)==0 | rem(v(a),5)==0)
v(a) = v(a)*2;
elseif v(a)<0 & v(a)>-5
v(a) = v(a)^3;
end
end
disp(v)
ANSWER:
Columns 1 through 7
10 17 -27 8 0 -7 24
Columns 8 through 14
30 40 -6 12 4 -7 16
clc,clear
n=0; a=0; b=1; s=[];
x=input('enter the vale for exp :');
while b>0.0001 & n<=30
b=x^n/factorial(n);
n=n+1; s(n)=b;
end
if n>30
fprintf('more than 30 terms are required\n')
else
sum(s)
end
ANSWER:
enter the vale for exp :2
ans = 7.3890
clc,clear
a=[4 6];
for x=3:20
a(x)=a(x-1)+a(x-2);
end
disp(a)
ANSWER:
Columns 1 through 3
4 6 10
Columns 4 through 6
16 26 42
Columns 7 through 9
68 110 178
Columns 10 through 12
Columns 13 through 15
Columns 16 through 18
Columns 19 through 20
21892 35422
clc,clear
format long
m=[5 10 20];
disp('pi ='), disp(pi),
disp('value for 5 10 & 20 are :')
for a=1:3
n=0:m(a);
val=sqrt(12)*sum((1/3).^n./(2.*n+1));
disp(val)
end
ANSWER:
pi =
3.141592653589793
value for 5 10 & 20 are :
3.950358224731334
3.950872463032491
3.950873690763143
clear,clc
format long
Ms=[100 100000 1000000];
for m=Ms
s=1;
for n=1:m
term =(2*n)^2/((2*n)^2-1);
s=s*term;
end
result=2*s;
compare=abs(result-pi);
fprintf('\nm=%.1i',m)
fprintf('\nresult=%.15f',result)
fprintf('\ndifference with pi is %.15f',compare)
end
ANSWER:
m=100
result=3.133787490628162
m=100000
result=3.141584799657247
m=1000000
result=3.141591868192149
clear,clc
scores=[73 91 37 81 63 66 50 90 75 43 88 80 79 69 26 82 89 99 71 59];
sort_scores=sort(scores,’descend’);
avg_scores=mean(sort_scores(1:8));
fprintf(‘The average of the top 8 scores is %.5f’,avg_scores)
ANSWER:
The average of the top 8 scores is 87.50000
clear,clc
angle = input('Please enter the angle in degrees: ');
angle_rad = deg2rad(angle);
n = 1;
an = angle_rad;
s = an;
s_prev = 0;
E=1;
while E > 0.000001
n = n + 1;
an = (-1)^(n-1) * angle_rad^(2*n-1) / factorial(2*n - 1);
s_prev = s;
s = s + an;
E = abs(s - s_prev) / abs(s_prev);
end
ANSWER:
Please enter the angle in degrees: 45
sin(45.0) = 0.707107
Please enter the angle in degrees: 195
sin(195.0) = -0.258819
function [Smax,Smin] = princstress(Sxx,Syy,Sxy)
%princstress Summary of this function goes here
% Calculate stresses
Smax = ((Sxx+Syy)/2)+sqrt(((Sxx+Syy)/2)^2+Sxy^2);
Smin = ((Sxx+Syy)/2)
sqrt(((Sxx+Syy)/2)^2+Sxy^2);
end
[a b]=princstress(190,145,110)
[x y]=princstress(14,-15,8)
ANSWER:
a = 89.777557864428104
b = -1.347775578644281e+02
x = 7.515609770940699
y = -8.515609770940699
HeatIn(95,80)
HeatIn(100,100)
ANSWER:
ans = 134
ans = 195
ANSWER:
ans = 2.605182156964312
ans = 7.000002391496738
ans = -1.718772023769644
function p = polyadd(p1,p2,operation)
n = length(p1) - length(p2);
if n ~ 0;
vectorpart = zeros(1,abs(n));
if n > 0
p2 = [vectorpart p2];
elseif n < 0
p1 = [vectorpart p1];
end
end
if operation == 'sub'
operator = -1;
else
operator = 1;
end
p = p1 + operator*p2;
end
p1 = [8 10 0 -5 13 -4 -2];
p2 = [4 0 7 0 6];
Addition = polyadd(p1,p2,'add')
Subtraction = polyadd(p1,p2,'sub')
Addition =
8 10 4 -5 20 -4 4
Subtraction =
8 10 -4 -5 6 -4 -8
n = length(p1) + length(p2) - 1;
p = zeros(1,n);
for i = 1:length(p1)
for j = 1:length(p2)
p(i+j-1) = p(i+j-1)+p1(i)*p2(j);
end
end
end
p1 = [-2 0 3 4 0 -7 8];
p2 = [5 0 -4 3 -5];
multiplication_by_polymult = polymult(p1,p2)
multiplication_by_conv = conv(p1,p2)
multiplication_by_polymult =
-10 0 23 14 -2 -42 37 8 -53 59 -40
multiplication_by_conv =
-10 0 23 14 -2 -42 37 8 -53 59 -40
Both polymult and conv produced the same results
clc,clear
% r^2 = 81 - h^2
% height = h + 9
% V = (1/3)(pi)(81-h^2)(h+9)
fplot(@(h)(pi/3).*(81-h.^2).*(h+9),[-9 9])
xlabel('h')
ylabel('V')
title('V-h Graph')
V = [-pi/3 -3*pi 27*pi 243*pi];
V500 = [V(1) V(2) V(3) V(4)-500];
r = roots(V500);
disp(['The value of h at V = 500 cubic inch is either ',num2str(r(2)),'
inches or ',num2str(r(3)),' inches correct to 4 decimal places.'])
h = fminbnd(@(h)(-pi/3).*(81-h.^2).*(h+9),-9,9);
disp(['The value of h at which the cone has the largest possible volume is
',num2str(h),' inches.'])
largestvolume = polyval(V,h);
disp(['The largest possible value of the volume of the cone is
',num2str(largestvolume),' cubic inch correct to 4 decimal places.'])
The value of h at V = 500 cubic inch is either 7.1751 inches or -2.5783
inches correct to 4 decimal places.
The value of h at which the cone has the largest possible volume is 3
inches.
The largest possible value of the volume of the cone is 904.7787 cubic
inch correct to 4 decimal places.
clc,clear
% x(x+5)(x+10) = 10098
% x^3 + 15x^2 + 50x - 10098 = 0
polyy = [1 15 50 -10098];
r = roots(polyy);
x = r(imag(r)==0);
fprintf('The three integers are %i, %i and %i. \n',x,x+5,x+10)
The four integers are either -14, -12, -10 and -8 or 8, 10, 12 and 14.
The largest possible value of the volume of the cone is 904.7787 cubic
inch correct to 4 decimal places.
clc
% Given data
T = [-20, 0, 20, 40, 60, 80, 100, 120]; % Temperature in °C
mu = [4, 0.38, 0.095, 0.032, 0.015, 0.0078, 0.0045, 0.0032]; %
Viscosity in Ns/m^2 (× 10^-5)
% Equation coefficients
a = coefficients(1);
b = coefficients(2);
c = coefficients(3);
clc
% Given data points
h = [-1000, 0, 3000, 8000, 15000, 22000, 28000];
T = [213.9, 212, 206.2, 196.2, 184.4, 172.6, 163.1];
% Fit a linear equation to the data
coefficients = polyfit(h, T, 1);
m = coefficients(1); % Slope
b = coefficients(2); % Intercept
% Calculate boiling temperature at 5,000 m
T_5000 = m * 5000 + b;
% Plot the data points and the equation
plot(h, T, 'o'); % Data points
hold on;
plot(h, m * h + b); % Linear equation
xlabel('Altitude (ft)');
ylabel('Boiling Temperature (°F)');
title('Boiling Temperature of Water at Various Altitudes');
legend('Data Points', 'Linear Equation');
grid on;
clc
t = [0, 1, 3, 4, 6, 7, 9];
NB = [500, 600, 1000, 1400, 2100, 2700, 4100];
% Fit an exponential function using a linear fit on the logarithmic
data
log_NB = log(NB);
p = polyfit(t, log_NB, 1);
% Extract the coefficients
alpha = p(1);
N0 = exp(p(2));
% Display the fitted equation
disp(['NB = ', num2str(N0), ' * exp(', num2str(alpha), ' * t)']);
% Estimate the number of bacteria after 5 hours
t_estimate = 5;
estimated_NB = N0 * exp(alpha * t_estimate);
disp(['Estimated number of bacteria after 5 hours: ',
num2str(estimated_NB)]);
% Generate points for the fitted curve
t_fit = 0:0.1:9;
NB_fit = N0 * exp(alpha * t_fit);
% Plot the actual data points and the fitted equation
plot(t, NB, 'ro', 'DisplayName', 'Actual Data');
hold on;
plot(t_fit, NB_fit, 'b-', 'DisplayName', 'Fitted Equation');
xlabel('Time (h)');
ylabel('Number of Bacteria (NB)');
legend('show');
NB = 496.7595 * exp(0.23921 * t)
Estimated number of bacteria after 5 hours: 1642.776
clc
% Given data
t = [0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0];
C = [1.7 3.1 5.7 9.1 6.4 3.7 2.8 1.6 1.2 0.8 0.7 0.6];
% Equation for C
C_eqn = @(t) a2 * t.^2 + a1 * t + a0;
% Estimate concentration at t = 2
t_estimation = 2;
C_estimation = C_eqn(t_estimation);