LAB SESSION #1:
REVIEW PROBLEM #1(a):
clear,clc
u=1;v=3;
A=(4*u);
B=(3*v);
C=A/B;
fprintf(' The answer is %2f.\n',C)
ANSWER:
The answer is 0.444444.
REVIEW PROBLEM #1(b):
clear,clc
u=1;v=3;
A=(2*(v^-2));
B=(u+v)^2;
C=A/B;
fprintf(' The answer is %2f.\n',C)
ANSWER:
The answer is 0.013889.
REVIEW PROBLEM #1(c):
clear,clc
u=1;v=3;
A=(v^3);
B=((v^3)-(u^3));
C=A/B;
fprintf(' The answer is %2f.\n',C)
ANSWER:
The answer is 1.038462.
REVIEW PROBLEM #1(d):
clear,clc
u=1;v=3;
A=(4/3);
B=(pi*(v^2));
C=A*B;
fprintf(' The answer is %2f.\n',C)
ANSWER:
The answer is 37.699112.
REVIEW PROBLEM #2:
clear,clc
total_eggs=4217;
eggs_per_box=36;
eggs_remain=fix(rem(total_eggs,eggs_per_box))
ANSWER:
eggs_remain = 5
REVIEW PROBLEM #3(a):
clear,clc
% case# 1 %
x=20;
A=sind(x);
B=cosd(x);
LHS=(A+B)^2
RHS=1+(A*B)*2
% case# 2 %
x=pi/10;
A=sind(x);
B=cosd(x);
LHS=(A+B)^2
RHS=1+(A*B)*2
ANSWER:
Case #1:
LHS =1.6428
RHS =1.6428
Case #2:
LHS = 1.0110
RHS =1.0110
REVIEW PROBLEM #1(b):
clear,clc
% case# 1 %
x=20;
A=sind(x);
B=cosd(x);
LHS=((1-(2*B))-(3*(B^2)))/((A)^2)
RHS=(1-3*B)/(1-B)
% case# 2 %
x=pi/10;
A=sind(x);
B=cosd(x);
LHS=((1-(2*B))-(3*(B^2)))/((A)^2)
RHS=(1-3*B)/(1-B)
ANSWER:
LHS = -30.1634
RHS = -30.1634
LHS =-1.3304e+05
RHS = -1.3304e+05
LAB SESSION #2:
REVIEW PROBLEM #1:
% Step 1: Calculate the decay constant (k)
half_life = 5730; % Half-life of carbon-14 in years
k = log(2) / half_life;
% Step 2: Calculate the estimated age (t)
f0 = 1; % Initial amount of carbon-14
f_t = 0.7745 * f0; % Amount of carbon-14 at time t
t = log(f_t / f0) / k;
% Step 3: Round the estimated age to the nearest year
estimated_age = round(t);
% Display the estimated age
disp(['The estimated age of the footprint is approximately '
num2str(estimated_age) ' years.']);
ANSWER:
The estimated age of the footprint is approximately -2112 years.
REVIEW PROBLEM #2:
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
REVIEW PROBLEM #3:
clear,clc;
k=401; %thermal conductivity in watt/degree celcius/meter
L=300; %length in cm
r1=3; %inner radius in cm
r2=5; %outer radius in cm
T1=100; %internal temperature in celcius
T2=20; %external temperature in celcius
q=2*pi*L*k*(T1-T2)/log(r2/r1)
ANSWER:
q = 1.1838e+08
REVIEW PROBLEM #4:
clear,clc;
a=27; b=43; c=57;
disp('part (a)')
alpha=acosd((a^2+b^2+c^2)/(2*b*c))
beta=acosd((b^2+a^2+c^2)/(2*a*c))
gamma=acosd((c^2+a^2+b^2)/(2*a*b))
Total=alpha+beta+gamma
disp('part (b)')
LHS=(b-c)/(b+c)
RHS=tand((1/2)*(beta-gamma))/tand((1/2)*(beta + gamma))
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
% Convert force vector to Newtons (1 lb = 4.44822 N)
force_N = force * 4.44822;
% Solve for the height of the pole (z-coordinate)
z = length_cable * force_N(3) / norm(force_N);
% Solve for the location of the base (x and y coordinates)
base = -length_cable * force_N(1:2) / norm(force_N(1:2));
% Display the results
disp(['Height of the pole (z-coordinate): ' num2str(z) ' ft']);
disp(['Location of the base (x, y coordinates): (' num2str(base(1)) ', '
num2str(base(2)) ') ft']);
ANSWERS:
Height of the pole (z-coordinate): -16 ft
Location of the base (x, y coordinates): (27.2, 20.4) 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.
A=600; % given area of triangle
a=10:0.1:120;
h=2*A./a;
q=atand(a./(2*h));
H=2+h+2./sind(q);
B=2*H.*tand(q);
AA=B.*H/2;
% Dimension of smallest sign
[AAmin,i]=min(AA)
amin=a(i)
hmin=h(i)
Answer:
AAmin =
844.1299
i=
273
amin =
37.2000
hmin =
32.2581
% Given data of projectile A
Va=560;
theta_a=43;
% Given data of projectile B
Vb=680;
theta_b=50;
g=9.81;
% Time of flight of projectile A & B
Tf_a=2*(Va*sind(theta_a))/g;
Tf_b=2*(Vb*sind(theta_b))/g;
TF=[Tf_a Tf_b];
% Determine which projectile hits the ground first
tf=min(TF);
% Create a vector of equally spaced time intervals
t=linspace(0,tf,11);
% Calculate the x and y components of the position
vector (rAB) at each time t
xA = Va * cosd(theta_a) * t;
yA = Va * sind(theta_a) * t - 0.5 * g * t.^2;
xB = Vb * cosd(theta_b) * t;
yB = Vb * sind(theta_b) * t - 0.5 * g * t.^2;
tbl=[t' xB' - xA' yB' - yA'];
% Displaying the results
disp(' t X_rAB Y_rAB')
disp(tbl)
Answer:
t X_rAB Y_rAB
0 0 0
0.0008 0.0214 0.1082
0.0016 0.0429 0.2164
0.0023 0.0643 0.3247
0.0031 0.0858 0.4329
0.0039 0.1072 0.5411
0.0047 0.1286 0.6493
0.0055 0.1501 0.7576
0.0062 0.1715 0.8658
0.0070 0.1930 0.9740
0.0078 0.2144 1.0822
h=2;% Height (m)
g=9.81; % Acceleration due to gravity (m/s^2)
% Calculate the initial velocity of ball
v=sqrt(2*g*h);
n=1:1:8;
% Calculate the time of first 8 bounces
t=((0.85).^(n-1)*v)/g;
tbl=[n' t'];
% results
disp(' n t')
disp(tbl)
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
the total charge 1.73
please enter payment (1,5,10,20 or 50):50
change = 0.0200
$20 $10 $5
$1 $0.25 $0.10
$0.05 $0.01
1 1 1
13 1 0
0 2
the total charge21.94
please enter payment
(1,5,10,20 or 50):5
insufficient payment
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
288 466 754
Columns 13 through 15
1220 1974 3194
Columns 16 through 18
5168 8362 13530
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
difference with pi is 0.007805162961631
m=100000
result=3.141584799657247
difference with pi is 0.000007853932546
m=1000000
result=3.141591868192149
difference with pi is 0.000000785397644
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
fprintf('sin(%.1f) = %.6f\n', angle, s);
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
function [x,y] = elipseplot(xc,yc,a,b)
%elipseplot Summary of this function goes here
% graph for elipse
theta = linspace(0, 2*pi, 360);
x = a*cos(theta) + xc;
y = b*sin(theta) + yc;
linspace(1)
plot(x, y, 'LineWidth', 2);
title('Graph of an Ellipse');
end
ANSWER:
elipseplot(3.5,2,8.5,3)
elipseplot(-5,1.5,4,8)
function HI= HeatIn(T,R)
%HeatIn Summary of this function goes here
% Detailed explanation goes here
C1 = -42.379;
C2 = 2.04901523;
C3 = 10.14333127;
C4 = -0.22475541;
C5 = 6.83783*10^(-3);
C6 = 5.481717*10^(-2);
C7 = 1.22874*10^(-3);
C8 = 8.5282*10^(-4);
C9 = 1.99*10^(-6);
HI = C1 + C2*T + C3*R +
C4*T*R + C5*T^2 + C6*R^2 ...
+ C7*R*T^2 + C8*T*R^2 +
C9*T^2*R^2 ;
HI = round(HI);
end
HeatIn(95,80)
HeatIn(100,100)
ANSWER:
ans = 134
ans = 195
function [y] = fifthroot(P)
%fifthroot Summary of this function goes here
% Detailed explanation goes here
x = [1 0 0 0 0 -P];
xi = P - polyval(x,P)/polyval(polyder(x),P);
while abs((polyval(x,xi)/polyval(polyder(x),xi))/xi) >= 0.00001
xi = xi - polyval(x,xi)/polyval(polyder(x),xi);
end
y = xi;
end
fifthroot(120)
fifthroot(16807)
fifthroot(-15)
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 three integers are 17, 22 and 27.
% 'The product of four consecutive even integers is 13440. Determine the
four integers.....'
clc,clear
% x(x+2)(x+4)(x+6) = 13440
% x^4 + 12x^3 + 44x^2 + 48x -13440 = 0
polyy = [1 12 44 48 -13440];
r = roots(polyy);
x = r(imag(r)==0);
integers1 = x(1) : 2 : x(1)+6;
integers2 = x(2) : 2 : x(2)+6;
fprintf('The four integers are either %.0f, %.0f, %.0f and %.0f or %.0f,
%.0f, %.0f and %.0f. \n', ...
integers1(1),integers1(2),integers1(3),integers1(4),integers2(1),integers2
(2),integers2(3),integers2(4))
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)
% Convert temperature from °C to Kelvin
T_K = T + 273.15;
% Take the natural logarithm of viscosity
ln_mu = log(mu);
% Curve fitting using polyfit
coefficients = polyfit(T_K, ln_mu, 2);
% Equation coefficients
a = coefficients(1);
b = coefficients(2);
c = coefficients(3);
% Equation: ln_mu = a*T_K^2 + b*T_K + c
% Estimating viscosity at 150 °C
T_150 = 150 + 273.15;
ln_mu_150 = a*T_150^2 + b*T_150 + c;
mu_150 = exp(ln_mu_150);
% Display the equation and estimated viscosity at 150 °C
fprintf('Equation: ln_mu = %.4f*T^2 + %.4f*T + %.4f\n', a, b, c);
fprintf('Estimated viscosity at 150 °C: %.4e Ns/m^2\n', mu_150);
% Plotting the data and equation
figure;
plot(T, mu, 'ro', 'MarkerSize', 8); % Data points
hold on;
T_range = linspace(min(T), max(T), 100);
mu_fit = exp(a*T_range.^2 + b*T_range + c); % Equation values
plot(T_range, mu_fit, 'b-', 'LineWidth', 1.5); % Equation curve
hold off;
xlabel('Temperature (°C)');
ylabel('Viscosity (Ns/m^2)');
title('Viscosity of SAE 10W oil');
legend('Data', 'Equation');
grid on;
Equation: ln_mu = 0.0003*T^2 + -0.2686*T + 47.2075
Estimated viscosity at 150 °C: 5.0817e-03 Ns/m^2
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];
% Degree of the polynomial
n = 2;
% Fit the data using polynomial regression
coefficients = polyfit(t, C, n);
% Extract the coefficients
a2 = coefficients(1);
a1 = coefficients(2);
a0 = coefficients(3);
% 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);
% Display coefficients and estimation
fprintf('Coefficients: a2 = %.4f, a1 = %.4f, a0 = %.4f\n', a2, a1,
a0);
fprintf('Estimated concentration at t = 2: %.4f g/L\n',
C_estimation);
% Plot the data points and the equation
figure;
plot(t, C, 'ro', 'MarkerSize', 8); % Data points
hold on;
t_plot = linspace(min(t), max(t), 100);
C_plot = C_eqn(t_plot);
plot(t_plot, C_plot, 'b-', 'LineWidth', 2); % Equation
xlabel('Time (h)');
ylabel('Concentration (g/L)');
title('Concentration vs. Time');
legend('Data', 'Equation');
grid on;
Coefficients: a2 = -0.4062, a1 = 1.7815, a0 = 2.8273
Estimated concentration at t = 2: 4.7655 g/L