SlideShare a Scribd company logo
1 of 46
Download to read offline
LAB SESSION 01
Question 01: (Script)
%FAIQ ALI ME-22150
u=1; v=3;
(4*u)/(3*v) %(Part_a)
(2*v^-2)/((u+v)^2) %(Part_b)
(v^3)/((v^3)-(u^3)) %(Part_c)
(4/3)*pi*(v^2) %(Part_d)
Command Window:
Question 02: (Script)
%FAIQ ALI ME-22150
4217-fix(4217/36)*36
Command Window:
Question 03: (Script File)
%FAIQ ALI ME-22150
disp('Part_a')
x=20;
LHS_a=(sind(x)+cosd(x))^2 %LEFTHANDSIDE
RHS_a=1+(2*sind(x)*cosd(x))%RIGHTHANDSIDE
x=pi/10;
LHS_a=(sind(x)+cosd(x))^2 %LEFTHANDSIDE
RHS_a=1+(2*sind(x)*cosd(x))%RIGHTHANDSIDE
disp('Part_b')
x=20;
LHS_b=(1-2*cosd(x)-3*(cosd(x))^2)/((sind(x))^2) %LEFTHANDSIDE
RHS_b=(1-3*cosd(x))/(1-cosd(x)) %RGHTHANDSIDE
x=pi/10;
LHS_b=(1-2*cosd(x)-3*(cosd(x))^2)/((sind(x))^2) %LEFTHANDSIDE
RHS_b=(1-3*cosd(x))/(1-cosd(x)) %RIGHTHANDSIDE
Command Window:
LAB SESSION 02
Question 01: (Script)
%FAIQ ALI ME-22150
% Find constant k from knowing half-life T
% f(T)=0.5f(0) = f(0)exp(k*T) as half of the element decay with time
% 0.5 = exp(k*T)
% k*T = log(0.5)
T = 5730; % half-life in years
k = log(0.5)/T
% Find age of the sample t
% f(t) = 0.7745f(0) & f(t) = f(0)exp(k*t)
% 0.7745 = exp(k*t) % t
= log(0.7745)/k
t = round(log(0.7745)/k)
Command Window:
Question 02: (Script File)
%FAIQ ALI ME-22150
c=300E6; %speed of light
x_p=530E9;
x_s=630E9;
v=c*((1-(x_p/x_s)^2)/((x_p/x_s)^2+1))
Command Window:
Question 03: (Script File)
%FAIQ ALI ME-22150
k=401; %thermal conductivity in watts/degree Celsius/meter
L=300; %length in cm
r1=3; %inner radius in cm
r2=5; %outer radius in cm
T1=100; %internal temperature in Celsius
T2=20; %external temperature in Celsius
q=2*pi*L*k*(T1-T2)/log(r2/r1)
Command Window:
Question 04: (Script File)
%ABDUL KHALIQUE ME-22149
clear,clc
a=27; b=43;
c=57;
%PART_(a)
Gamma=acosd((a^2+b^2-c^2)/(2*a*b))
Alpha=acosd((b^2+c^2-a^2)/(2*b*c))
Beta=180-(Alpha+Gamma)
%PART_(b)
LHS=(b+c)/(b-c) %LEFTHANDSIDE
RHS=tand((Beta+Gamma)/2)/tand((Beta-Gamma)/2) %RIGHTHANDSIDE
LAB SESSION 03
Question 01: (Script File)
%FAIQ ALI ME-22150
%PART_(a)
anine=(1:9)
%PART_(b)
MA(1:4,1:3)=12
%PART_(c)
E(2:4,3:5)=[1:3;4:6;7:9]
Command Window:
LAB SESSION 04
Question 01: (Script File)
%FAIQ ALI ME-22150
F1=600*[cosd(4/5) 0 sind(4/5)];
F2=400*[cosd(60) cosd(90) cosd(120)];
FR=F1+F2;
Magnitude_FR=sqrt(sum(FR.^2));
Alpha=acosd(FR(1)/Magnitude_FR);
Beta=acosd(FR(2)/Magnitude_FR);
Gamma=acosd(FR(3)/Magnitude_FR);
fprintf(['The Resultant Force Is {%.2fi + %ij %.2fk}kN.n''Its Magnitude
Is %.2f kN.n''Its Direction Cosines Are %.4f, %.4f & %.4f Degrees
Respectively.n'],FR(1),FR(2),FR(3),Magnitude_FR,Alpha,Beta,Gamma)
Question 04: (Script File)
%FAIQ ALI ME-22150
F1=750*[cosd(45)*cosd(30) cosd(45)*sind(30) -sind(45)];
FR=[300 650 250];
F_F=FR-F1;
Magnitude_F=sqrt(sum(F_F.^2));
A=acosd(F_F(1)/Magnitude_F);
B=acosd(F_F(2)/Magnitude_F); C=acosd(F_F(3)/Magnitude_F);
fprintf(['The Magnitude Of Force ''F'' Is %.4f kN.n''The Direction
Cosines Are %.4f, %.4f & %.4f DegreesRespectively.n'],Magnitude_F,A,B,C)
Command Window:
Question 05: (Script File)
%FAIQ ALI ME-22150
F=[-120 -90 -80];
Magnitude_F=sqrt(sum(F.^2));
Unit_Vector=F/Magnitude_F;
Position_Vector=34*Unit_Vector;
Coordinates=Position_Vector*(-1);
fprintf('A(%i,%i,%i).n',Coordinates)
Command Window:
Question 04: (Script File)
%FAIQ ALI ME-22150
O=[0 0 0];
A=[3 3 -2];
F_1=[-20 10 30];
r_OA=A-O;
Mo=cross(r_OA,F_1);
Magnitude_M=sqrt(sum(Mo.^2));
fprintf('The Magnitude Of Moment ''Mo'' Produced By The Force ''F1''
About Point ''O'' Is %.4f kN-m.n',Magnitude_M)
Command Window:
Question 05: (Script File)
%FAIQ ALI ME-22150
mi=[0.5 0.8 0.2 1.1 0.4 0.9];
xi=[-10 -18 -7 5 0 25];
yi=[8 6 11 12 -8 -20];
zi=[32 19 2 -9 -6 8];
X=mi.*xi./mi;
Y=mi.*yi./mi; Z=mi.*zi./mi; fprintf(['The Centre Of Mass OfParticle
''A'' Is At A(%i, %i, %i).n' 'The Centre Of Mass Of Particle ''B'' Is
At B(%i, %.0f,%i).n' 'The Centre Of Mass Of Particle ''C'' Is At C(%i,
%i,%i).n' 'The Centre Of Mass Of Particle ''D'' Is At D(%i, %i,%i).n'
'The Centre Of Mass Of Particle ''E'' Is At E(%i, %i,%.0f).n' 'The
Centre Of Mass Of Particle ''F'' Is At F(%i, %i,%i).n'],X(1),Y(1),Z(1),
X(2),Y(2),Z(2),X(3),Y(3),Z(3),X(4),Y(4),Z(4),X(5),Y(5),Z(5),X(6),Y(6),Z
(6))
X=sum(mi.*xi)./sum(mi);
Y=sum(mi.*yi)./sum(mi); Z=sum(mi.*zi)./sum(mi); disp(' ') fprintf('The
Centre Of Mass Of The Whole System Is Located At G(%.4f, %. 4f,
%.4f).n',X,Y,Z)
LAB SESSION 05
Question 01: (Script File)
%FAIQ ALI ME-22150
Running_Speed=8.6 %ft/s;
Swimming_Speed=3.9 %ft/s;
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))
Command Window:
Question 02: (Script File)
%FAIQ ALI ME-22150
a=10:.1:120;
h=2*600./a;
theta=atan(a./(2*h));
height=h+2+2./sin(theta);
base=2*height.*tan(theta);
[min_area indx] = min(0.5*base.*height);
inner_base=a(indx) inner_height=h(indx)
outer_base=base(indx)
outer_height=height(indx)
Command Window:
%FAIQ ALI ME-22150
Vo1=560;
Theta_1=43; Vo2=680; Theta_2=50; g=9.81;
Tf_1=2*Vo1*sind(Theta_1)/g; Tf_2=2*Vo2*sind(Theta_2)/g;
fprintf('The First Projectile Will Hit The Ground First in %.4f Seconds.
n',Tf_1)
t1=linspace(0,Tf_1,11);
t2=linspace(0,Tf_2,11);
Vx1=Vo1*cosd(Theta_1)*t1;
Vy1=Vo1*sind(Theta_1)*Tf_10.5*g*t1.^2;
Vx2=Vo2*cosd(Theta_2)*t2;
Vy2=Vo2*sind(Theta_2)*Tf_1-
0.5*g*t2.^2; r_1=sqrt(Vx1.^2+Vy1.^2);
r_2=sqrt(Vx2.^2+Vy2.^2);
R_AB=r_2-r_1; disp(' ') ;
disp(' Time R_AB')
disp(' ')
disp([t1'R_AB'])
Command Window:
Question 02: (Script File)
%FAIQ ALI ME-22150
h=input('Enter Height In Meters : '); g=9.81;
Bounces=input('Enter the number of bounces as an array in increasing order
: ');
Rebound_V=sqrt(2*g*h);
V=0.85*Rebound_V./Bounces;
Time=[1:length(Bounces)];
Time(1)=0;
Time(2:length(Bounces)+1)=V./g; disp(' ')
disp(' Bounce Number Time') disp(' ')
disp([Bounces' Time([1: length(Bounces)])'])
Command Window:
LAB SESSION 06
Question 01: (Script File)
%FAIQ ALI ME-22150
t=0:.01:4;
x=4.219*(exp(-1.58*t)-exp(-6.32*t));
v=26.67*exp(-6.32*t)-6.67*exp(-1.58*t);
subplot(2,1,1)
plot(t,x)
title('Railroad Bumper Response')
ylabel('Position, m')
subplot(2,1,2)
plot(t,v)
ylabel('Speed, m/s')
xlabel('Time, s')
Command Window:
Question 02: (Script File)
%FAIQ ALI ME-22150
P=0:200;
Q=1020*sqrt(P).*(1-0.01*sqrt(P));
plot(P,Q)
title('Small Community Firefighting Water Needs')
xlabel('Population,Thousands')
ylabel('WaterDemand,gal/min')
Command Window:
LAB SESSION 07
Question 01: (Script File)
%FAIQ ALI ME-22150
clc,clear
for k=1:3
disp('For the Equation ax^2+bx+c') a=input('Enter a: ');
b=input('Enter b: ');
c=input('Enter c: ');
D=b^2-4*a*c;
if D<0
fprintf('n The equation has no real root.nn')
elseif D==0
root=-b/(2*a);
fprintf('n The Equation has One root, n')
fprintf(' %.3fnn',root)
else
r1=(-b+sqrt(D))/(2*a);
r2=(-b-sqrt(D))/(2*a);
fprintf('n The Equation has two roots, n')
fprintf(' %.3f and %.3fnn',r1,r2)
end
end
Question 02: (Script File)
%FAIQ ALI ME-22150
for k=1:2
gender=input('Please input your gender (male or female): ','s');
age=input('Please input your age: ');
RHR=input('Please enter your resting heart rate: ');
fit=input('Please enter your fitness level (low, medium, or high:
','s');
gender = lower(gender);
fit = lower(fit);
switch fit
case 'low'
INTEN=0.55;
case 'medium'
INTEN=0.65;
case 'high'
INTEN=0.8;
end
switch gender
case 'male'
THR=((220-age)-RHR)*INTEN+RHR;
case 'female'
THR=((206-0.88*age)-RHR)*INTEN+RHR;
end
fprintf('nThe recommended training heart rate is %.0fnn',THR);
end
Command Window:
Question 03: (Script)
%FAIQ ALI ME-22150
for j=1:2
W=input('Please input your weight in lb: ');
h=input('Please input your height in in: ');
BMI=703*W/h^2;
if BMI<18.5
fprintf('nYour BMI value is %.1f, which classifies you as underweightnn',BMI)
elseif BMI<25
fprintf('nYour BMI value is %.1f, which classifies you as normalnn', BMI)
elseif BMI<30
fprintf('nYour BMI value is %.1f, which classifies you as overweightnn',BMI)
else
fprintf('nYour BMI value is %.1f, which classifies you as obesenn', BMI)
end
end
Command Window:
Question 04: (Script File)
%FAIQ ALI ME-22150
for j=1:3
n(1:8)=0;
cost=randi([1 5000],1,1)/100;
fprintf('The total charge is $%.2fn',cost)
pay=input('Please enter payment (1, 5, 10, 20, or 50): ');
if pay<cost
fprintf('Insufficient Paymentnn')
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>=.25
n(5)=n(5)+1;
change=change-.25
end
while change>=.10
n(6)=n(6)+1;
change=change-.10;
end
if change>=.05;
n(7)=1;
change=change-.05;
end
change+.000001;
while change>=.01
n(8)=n(8)+1;
change=change-.01;
end
end
fprintf('n $20 $10 $5 $1 $0 $0.25 $0.10 $0.05 $0.01n')
fprintf(' %i',n)
Command Window
Question 05: (Script File)
%FAIQ ALI ME-22150
for j=1:3
p=input('Please enter the pressure: ');
old=input('Please enter the units (Pa, psi, atm, or torr): ','s');
new=input('Please enter the desired units (Pa, psi, atm, or 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%snn',pnew,pnew)
COMMAND WINDOW:
Question 06: (Script File)
%FAIQ ALI ME-22150
time=input('Enter the time of the call (day,evening,or night):','s');
duration=input('Enter the duration of the call in minutes: ');
duration=ceil(duration);
rate_day=0.10;
rate_evening=0.04;
rate_night=0.02;
switch time
case 'day'
cost=duration*rate_day;
case'evening'
cost=duration*rate_evening;
case 'night'
cost=duration*rate_night;
otherwise
error('invalid time sepecified');
end
if duration > 10
if duration <=30
cost=cost+1.00+(duration-10)*0.08;
else
cost=cost+1.00+20*0.08+(duration-30)*0.06;
end
end
fprintf('The cost of the call is %.2fn',cost);
Command Window:
LAB SESSION 08
Question 01: (Script File)
%FAIQ ALI ME-22150
V = [5, 17, -3, 8, 0, -7, 12, 15, 20, -6, 6, 4, -7, 16];
for i = 1:length(V)
if V(i) > 0 && (mod(V(i), 3) == 0 || mod(V(i), 5) == 0)
V(i) = V(i) * 2;
end
end
j = 1;
while j <= length(V)
if V(j) < 0 && V(j) > -5
V(j) = V(j) ^ 3;
j = j + 1; % Skip to next element
end
j = j + 1;
end disp(V);
Command Window:
Question 04: (Script File)
% FAIQ ALI ME-22150
x = 2;
term = 1;
sum = 1; n = 1;
while abs(term) >= 0.0001 && n <= 30
term = term * x / n;
sum = sum + term;
n = n + 1; end
if n > 30 && abs(term) >= 0.0001
disp('More than 30 terms are needed.');
else
disp(['e^', num2str(x), ' = ', num2str(sum)]);
end
Command Window:
Question 03 (Script File)
% FAIQ ALI ME-22150
% Input parameters
n = 4; % or n = 6
firstElement = 1;
secondElement = 2;
% Construct the matrix
fibMatrix = zeros(n,n);
fibMatrix(1, 1) = firstElement;
fibMatrix(1, 2) = secondElement;
for i = 2:n for j = 1:n-i+1
fibMatrix(i, j) = fibMatrix(i-1, j) + fibMatrix(i-1,j+1);
end
end
disp(['Matrix of order ', num2str(n), ' with firsttwo elements:'])
num2str(firstElement), ', ', num2str(secondElement)]);
disp(fibMatrix);
% Verify determinant is zero
determinant = det(fibMatrix);
disp(['Determinant of the matrix: ', num2str(determinant)]);
Command Window
Question 04: (Script File)
%FAIQ ALI ME-22150
m_values = [5, 10, 20];
for m = m_values
sum = 0;
n = 0;
while true
term = (-1/3)^n / (2*n + 1);
sum = sum + term;
n = n + 1;
if abs(term) < 1e-15
break;
end
end
% Display the result and compare with ?
disp(['For m = ', num2str(m)]);
disp(['Result: ', num2str(sqrt(12)*sum)]);
disp(['Comparison with pi: ', num2str(pi)]);
disp(' ');
end
Command Window
Question 05: (Script File)
%FAIQ ALI ME-22150
m_values = [100, 100000, 1000000];
for m = m_values
product = 1;
n = 1; while true
term = (2^(2*n))/(2^(2*n) - 1);
product = product * term;
n = n + 1;
if n > m
break;
end
end
disp(['For m = ', num2str(m)]);
disp(['Result: ', num2str(2*product)]);
disp(['Comparison with pi: ', num2str(pi)]);
disp('')
end
Question 06: (Script File)
%FAIQ ALI ME-22150
scores = [73, 91, 37, 81, 63, 66, 50, 90, 75, 43, 88, 80, 79, 69, 26,
82, 89, 99, 71, 59];
sorted_scores = sort(scores, 'descend');
top_scores = sorted_scores(1:8);
average = mean(top_scores); %
Display the average
disp(['Average of the top 8 scores: ', num2str(average)]);
Command Window
Question 07: (Script File)
%FAIQ ALI ME-22150
x_degrees = input('Enter the angle in degrees: ');
x_radians = deg2rad(x_degrees);
term = x_radians;
sum = term;
n = 1;
estimated_error = abs(term/sum);
while estimated_error > 1e-5
term = (-1)^n * (x_radians^(2*n+1)) / factorial(2*n +1);
sum = sum + term;
n = n + 1;
estimated_error = abs(term / sum);
end
disp(['sin(', num2str(x_degrees), ') = ', num2str(sum)]);
disp(['Comparison with calculator: ',num2str(sin(x_radians))]);
Command Window
LAB SESSION 09
Question 01: (Script)
% FAIQ ALI ME-22150
function [Smax,Smin] = princstress(Sxx, Syy, Sxy) %Calculates
princstress, Pricipal Stress, using the 3 stress components
Smax=((Sxx+Syy)/2)+(sqrt(((Sxx-Syy)/2)^2+(Sxy^2)));
Smin=((Sxx+Syy)/2)-(sqrt(((Sxx-Syy)/2)^2+(Sxy^2)));
fprintf('Maximum Principal Stress: %.4fn', Smax);
fprintf('Minimum Principal Stress: %.4fn', Smin);
end
Command Window:
a) Maximum Principal Stress: 177.8902
Minimum Principal Stress: -222.8902
ans = 177.8902
b) Maximum Principal Stress: 16.0605
Minimum Principal Stress: -17.0605
ans = 16.0605
Question 02: (Script)
%FAIQ ALI ME-22150
function ellipseplot(xc,yc,a,b)
%ellipseplot calculates and plots the ellipse with xc center
and yc center
theta = linspace(0, 2*pi, 100);
x = xc + a * cos(theta);
y = yc + b * sin(theta); plot(x, y);
xlabel('x');
ylabel('y');
title('Ellipse Plot');
end
Command Window:
Question 03: (Script)
%FAIQ ALI ME-22150
function [HI] = HeatIn(T,R)
%HeatIn calcualtes Heat index using Temperature and R
humidity
C1=-41.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;
HIx=C1+C2*T+C3*R+C4*T*R+C5*(T^2)+C6*(R^2)+C7*(T^2)*R+C8*T*( R^ 2
)+C9*(T^2)*(R^2);
HI=round(HIx);
end
Command Window:
Question 04: (Script)
%FAIQ ALI ME-22150
function [y] = fifthroot(P)
% Function calculates the fifth root of the number
P i = 1;
E = 1;
X(1) = P;
while E > 0.00001
i = i + 1;
X(i) = X(i-1) - ((X(i-1)^5 - P) / (5*(X(i-1))^4));
E = abs((X(i) - X(i-1)) / X(i-1)); e
end
y = X(i);
end
Command Window:
LAB SESSION 10
Question 01: (Script)
%FAIQ ALI ME-22150
disp('addition');
p1=[8 10 0 -5 13 -4 -2];
p2=[4 0 7 0 6];
p_add=p1+[0 0 p2];
disp(p_add)
disp('subtraction');
p_subtract=p1-[0 0 p2];
disp(p_subtract);
Command Window:
Question 02: (Script)
%FAIQ ALI ME-22150
disp('multiplication');
a1=[-2 0 3 4 0 -7 8];
a2=[5 0 -4 3 -5];
b=conv(a1,a2);
disp(b)
Command Window:
Question 03: (Script)
%FAIQ ALI ME-22150
R=9; V=500;
h=9:-0.2:-9;
% Part(a)
p=[-1 -R R^2 R^3];
Vh=polyval(p,h)*pi/3;
%Part(b)
plot(h,Vh);
xlabel('h (in.)');
ylabel('Volume (in^3)');
% Part (c)
disp('Part (c)');
hV500=[-1 -R R^2 R^3-3*V/pi];
h500=roots(hV500); disp(h500);
%Part(d)
disp('Part (d)');
Vpd=polyder(p);
rVmax=roots(Vpd);
disp(rVmax);
Vmax=polyval(p,rVmax(2))*pi/3;
COMMAND WINDOW:
Question 04: (Script)
%FAIQ ALI ME-22150
p1=[1 0]; p2=[1 5];
p3=[1 10];
p12=conv(p1,p2);
p=conv(p12,p3);
n=length(p);
p(n)=p(n)-10098;
s=roots(p)
COMMAND WINDOW
Question 05: (Script)
%FAIQ ALI ME-22150
% Find the cube root of 13,440
cube_root = nthroot(13440, 3);
% Round the cube root to the nearest integer
integer_root = round(cube_root);
% Calculate the four consecutive integers
integers = integer_root - 1 : integer_root + 2;
% Display the consecutive integers
disp(integers);
COMMAND WINDOW:
LAB SESSION 10
Question 01: (Script)
% FAIQ ALI ME-22150
T = [-20, 0, 20, 40, 60, 80, 100, 120];
d = [4, 0.38, 0.095, 0.032, 0.015, 0.0078, 0.0045, 0.0032];
% Fit a quadratic equation using polyfit
pf=polyfit(T,log(d),4);
% Estimate viscosity at 150 degrees Celsius
T_150=exp(polyval(pf,150));
% Plotting
x_cal=-20:.01:120;
y_cal=exp(polyval(pf,x_cal));
plot(T,d,'o',x_cal,y_cal,'r-', 'LineWidth', 1.5)
xlabel('Temperature (K)');
ylabel('Viscosity (Ns/m^2)');
title('Viscosity of Oil');
legend('Data Points', 'Fitted Equation');
grid on
fprintf('Estimated viscosity at 150 °C: %.4f *10Nsm^2n',T_150)
COMMAND WINDOW:
Question 02: (Script)
h_ft = [-1000, 0, 3000, 8000, 15000, 22000, 28000]; % Altitude in feet
T_F = [213.9, 212, 206.2, 196.2, 184.4, 172.6, 163.1]; % Boiling
temperature in Fahrenheit
% Convert altitude from feet to meters
h_m = h_ft * 0.3048;
% Fit a linear equation using polyfit
coeff = polyfit(h_m, T_F,2);
% Calculate boiling temperature at 5,000 m
h_5000 = 5000;
T_5000_F = polyval(coeff,h_5000);
% Plotting
figure;
h_plot = linspace(min(h_m), max(h_m), 100);
T_plot = polyval(coeff,h_plot);
plot(h_m, T_F, 'bo',h_plot, T_plot, 'r-', 'LineWidth', 1.5); % Data
points
xlabel('Altitude (m)');
ylabel('Boiling Temperature (°C)');
title('Boiling Temperature of Water at Different Altitudes');
legend('Data Points', 'Fitted Equation');
fprintf('Boiling temperature at 5,000 m is %.2f °Fn',T_5000_F);
COMMAND WINDOW:
Question 03: (Script)
%FAIQ ALI ME-22150
t = [0, 1, 3, 4, 6, 7, 9]; % Time in hours
NB = [500, 600, 1000, 1400, 2100, 2700, 4100];
% Fit an exponential function using the polyfit
coeff = polyfit(t, log(NB),6);
% Estimate the number of bacteria after 5 hours
t_5 = 5;
NB_5 = exp(polyval(coeff,t_5));
% Plotting
t_plot = linspace(min(t), max(t), 1000);
NB_plot = exp(polyval(coeff,t_plot));
plot(t, NB, 'bo',t_plot, NB_plot, 'r-', 'LineWidth',1.5);
xlabel('Time (hours)');
ylabel('Number of Bacteria');
title('Growth of Bacteria over Time'); legend('Data
Points', 'Fitted Equation');
% Display estimated number of bacteria after 5 hours
fprintf('Estimated number of bacteria after 5 hours: %.2fn', NB_5);
COMMAND WINDOW:

More Related Content

Similar to FAIQ MANUAL.pdf

Fourier series example
Fourier series exampleFourier series example
Fourier series example
Abi finni
 
Please use the same variables and only write the TODO part #!-usr-bi.pdf
Please use the same variables and only write the TODO part   #!-usr-bi.pdfPlease use the same variables and only write the TODO part   #!-usr-bi.pdf
Please use the same variables and only write the TODO part #!-usr-bi.pdf
asenterprisestyagi
 

Similar to FAIQ MANUAL.pdf (20)

Critical buckling load geometric nonlinearity analysis of springs with rigid ...
Critical buckling load geometric nonlinearity analysis of springs with rigid ...Critical buckling load geometric nonlinearity analysis of springs with rigid ...
Critical buckling load geometric nonlinearity analysis of springs with rigid ...
 
3.pdf
3.pdf3.pdf
3.pdf
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
 
array
arrayarray
array
 
Slide set 6 Strings and pointers.pdf
Slide set 6 Strings and pointers.pdfSlide set 6 Strings and pointers.pdf
Slide set 6 Strings and pointers.pdf
 
MH prediction modeling and validation in r (2) classification 190709
MH prediction modeling and validation in r (2) classification 190709MH prediction modeling and validation in r (2) classification 190709
MH prediction modeling and validation in r (2) classification 190709
 
The Moore-Spiegel Oscillator
The Moore-Spiegel OscillatorThe Moore-Spiegel Oscillator
The Moore-Spiegel Oscillator
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
Vcs5
Vcs5Vcs5
Vcs5
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
Regression and Classification with R
Regression and Classification with RRegression and Classification with R
Regression and Classification with R
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
Struct examples
Struct examplesStruct examples
Struct examples
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptx
 
Please use the same variables and only write the TODO part #!-usr-bi.pdf
Please use the same variables and only write the TODO part   #!-usr-bi.pdfPlease use the same variables and only write the TODO part   #!-usr-bi.pdf
Please use the same variables and only write the TODO part #!-usr-bi.pdf
 
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
 
Answers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And EngineersAnswers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
 
statistics assignment help
statistics assignment helpstatistics assignment help
statistics assignment help
 
The solution manual of programming in ansi by Robin
The solution manual of programming in ansi by RobinThe solution manual of programming in ansi by Robin
The solution manual of programming in ansi by Robin
 

Recently uploaded

Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 

Recently uploaded (20)

Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 

FAIQ MANUAL.pdf

  • 1. LAB SESSION 01 Question 01: (Script) %FAIQ ALI ME-22150 u=1; v=3; (4*u)/(3*v) %(Part_a) (2*v^-2)/((u+v)^2) %(Part_b) (v^3)/((v^3)-(u^3)) %(Part_c) (4/3)*pi*(v^2) %(Part_d) Command Window:
  • 2. Question 02: (Script) %FAIQ ALI ME-22150 4217-fix(4217/36)*36 Command Window:
  • 3. Question 03: (Script File) %FAIQ ALI ME-22150 disp('Part_a') x=20; LHS_a=(sind(x)+cosd(x))^2 %LEFTHANDSIDE RHS_a=1+(2*sind(x)*cosd(x))%RIGHTHANDSIDE x=pi/10; LHS_a=(sind(x)+cosd(x))^2 %LEFTHANDSIDE RHS_a=1+(2*sind(x)*cosd(x))%RIGHTHANDSIDE disp('Part_b') x=20; LHS_b=(1-2*cosd(x)-3*(cosd(x))^2)/((sind(x))^2) %LEFTHANDSIDE RHS_b=(1-3*cosd(x))/(1-cosd(x)) %RGHTHANDSIDE x=pi/10; LHS_b=(1-2*cosd(x)-3*(cosd(x))^2)/((sind(x))^2) %LEFTHANDSIDE RHS_b=(1-3*cosd(x))/(1-cosd(x)) %RIGHTHANDSIDE Command Window:
  • 4. LAB SESSION 02 Question 01: (Script) %FAIQ ALI ME-22150 % Find constant k from knowing half-life T % f(T)=0.5f(0) = f(0)exp(k*T) as half of the element decay with time % 0.5 = exp(k*T) % k*T = log(0.5) T = 5730; % half-life in years k = log(0.5)/T % Find age of the sample t % f(t) = 0.7745f(0) & f(t) = f(0)exp(k*t) % 0.7745 = exp(k*t) % t = log(0.7745)/k t = round(log(0.7745)/k) Command Window:
  • 5. Question 02: (Script File) %FAIQ ALI ME-22150 c=300E6; %speed of light x_p=530E9; x_s=630E9; v=c*((1-(x_p/x_s)^2)/((x_p/x_s)^2+1)) Command Window:
  • 6. Question 03: (Script File) %FAIQ ALI ME-22150 k=401; %thermal conductivity in watts/degree Celsius/meter L=300; %length in cm r1=3; %inner radius in cm r2=5; %outer radius in cm T1=100; %internal temperature in Celsius T2=20; %external temperature in Celsius q=2*pi*L*k*(T1-T2)/log(r2/r1) Command Window:
  • 7. Question 04: (Script File) %ABDUL KHALIQUE ME-22149 clear,clc a=27; b=43; c=57; %PART_(a) Gamma=acosd((a^2+b^2-c^2)/(2*a*b)) Alpha=acosd((b^2+c^2-a^2)/(2*b*c)) Beta=180-(Alpha+Gamma) %PART_(b) LHS=(b+c)/(b-c) %LEFTHANDSIDE RHS=tand((Beta+Gamma)/2)/tand((Beta-Gamma)/2) %RIGHTHANDSIDE
  • 8. LAB SESSION 03 Question 01: (Script File) %FAIQ ALI ME-22150 %PART_(a) anine=(1:9) %PART_(b) MA(1:4,1:3)=12 %PART_(c) E(2:4,3:5)=[1:3;4:6;7:9] Command Window:
  • 9. LAB SESSION 04 Question 01: (Script File) %FAIQ ALI ME-22150 F1=600*[cosd(4/5) 0 sind(4/5)]; F2=400*[cosd(60) cosd(90) cosd(120)]; FR=F1+F2; Magnitude_FR=sqrt(sum(FR.^2)); Alpha=acosd(FR(1)/Magnitude_FR); Beta=acosd(FR(2)/Magnitude_FR); Gamma=acosd(FR(3)/Magnitude_FR); fprintf(['The Resultant Force Is {%.2fi + %ij %.2fk}kN.n''Its Magnitude Is %.2f kN.n''Its Direction Cosines Are %.4f, %.4f & %.4f Degrees Respectively.n'],FR(1),FR(2),FR(3),Magnitude_FR,Alpha,Beta,Gamma)
  • 10. Question 04: (Script File) %FAIQ ALI ME-22150 F1=750*[cosd(45)*cosd(30) cosd(45)*sind(30) -sind(45)]; FR=[300 650 250]; F_F=FR-F1; Magnitude_F=sqrt(sum(F_F.^2)); A=acosd(F_F(1)/Magnitude_F); B=acosd(F_F(2)/Magnitude_F); C=acosd(F_F(3)/Magnitude_F); fprintf(['The Magnitude Of Force ''F'' Is %.4f kN.n''The Direction Cosines Are %.4f, %.4f & %.4f DegreesRespectively.n'],Magnitude_F,A,B,C) Command Window:
  • 11. Question 05: (Script File) %FAIQ ALI ME-22150 F=[-120 -90 -80]; Magnitude_F=sqrt(sum(F.^2)); Unit_Vector=F/Magnitude_F; Position_Vector=34*Unit_Vector; Coordinates=Position_Vector*(-1); fprintf('A(%i,%i,%i).n',Coordinates) Command Window:
  • 12. Question 04: (Script File) %FAIQ ALI ME-22150 O=[0 0 0]; A=[3 3 -2]; F_1=[-20 10 30]; r_OA=A-O; Mo=cross(r_OA,F_1); Magnitude_M=sqrt(sum(Mo.^2)); fprintf('The Magnitude Of Moment ''Mo'' Produced By The Force ''F1'' About Point ''O'' Is %.4f kN-m.n',Magnitude_M) Command Window:
  • 13. Question 05: (Script File) %FAIQ ALI ME-22150 mi=[0.5 0.8 0.2 1.1 0.4 0.9]; xi=[-10 -18 -7 5 0 25]; yi=[8 6 11 12 -8 -20]; zi=[32 19 2 -9 -6 8]; X=mi.*xi./mi; Y=mi.*yi./mi; Z=mi.*zi./mi; fprintf(['The Centre Of Mass OfParticle ''A'' Is At A(%i, %i, %i).n' 'The Centre Of Mass Of Particle ''B'' Is At B(%i, %.0f,%i).n' 'The Centre Of Mass Of Particle ''C'' Is At C(%i, %i,%i).n' 'The Centre Of Mass Of Particle ''D'' Is At D(%i, %i,%i).n' 'The Centre Of Mass Of Particle ''E'' Is At E(%i, %i,%.0f).n' 'The Centre Of Mass Of Particle ''F'' Is At F(%i, %i,%i).n'],X(1),Y(1),Z(1), X(2),Y(2),Z(2),X(3),Y(3),Z(3),X(4),Y(4),Z(4),X(5),Y(5),Z(5),X(6),Y(6),Z (6)) X=sum(mi.*xi)./sum(mi); Y=sum(mi.*yi)./sum(mi); Z=sum(mi.*zi)./sum(mi); disp(' ') fprintf('The Centre Of Mass Of The Whole System Is Located At G(%.4f, %. 4f, %.4f).n',X,Y,Z)
  • 14. LAB SESSION 05 Question 01: (Script File) %FAIQ ALI ME-22150 Running_Speed=8.6 %ft/s; Swimming_Speed=3.9 %ft/s; 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)) Command Window:
  • 15. Question 02: (Script File) %FAIQ ALI ME-22150 a=10:.1:120; h=2*600./a; theta=atan(a./(2*h)); height=h+2+2./sin(theta); base=2*height.*tan(theta); [min_area indx] = min(0.5*base.*height); inner_base=a(indx) inner_height=h(indx) outer_base=base(indx) outer_height=height(indx) Command Window:
  • 16. %FAIQ ALI ME-22150 Vo1=560; Theta_1=43; Vo2=680; Theta_2=50; g=9.81; Tf_1=2*Vo1*sind(Theta_1)/g; Tf_2=2*Vo2*sind(Theta_2)/g; fprintf('The First Projectile Will Hit The Ground First in %.4f Seconds. n',Tf_1) t1=linspace(0,Tf_1,11); t2=linspace(0,Tf_2,11); Vx1=Vo1*cosd(Theta_1)*t1; Vy1=Vo1*sind(Theta_1)*Tf_10.5*g*t1.^2; Vx2=Vo2*cosd(Theta_2)*t2; Vy2=Vo2*sind(Theta_2)*Tf_1- 0.5*g*t2.^2; r_1=sqrt(Vx1.^2+Vy1.^2); r_2=sqrt(Vx2.^2+Vy2.^2); R_AB=r_2-r_1; disp(' ') ; disp(' Time R_AB') disp(' ') disp([t1'R_AB']) Command Window:
  • 17. Question 02: (Script File) %FAIQ ALI ME-22150 h=input('Enter Height In Meters : '); g=9.81; Bounces=input('Enter the number of bounces as an array in increasing order : '); Rebound_V=sqrt(2*g*h); V=0.85*Rebound_V./Bounces; Time=[1:length(Bounces)]; Time(1)=0; Time(2:length(Bounces)+1)=V./g; disp(' ') disp(' Bounce Number Time') disp(' ') disp([Bounces' Time([1: length(Bounces)])']) Command Window:
  • 18. LAB SESSION 06 Question 01: (Script File) %FAIQ ALI ME-22150 t=0:.01:4; x=4.219*(exp(-1.58*t)-exp(-6.32*t)); v=26.67*exp(-6.32*t)-6.67*exp(-1.58*t); subplot(2,1,1) plot(t,x) title('Railroad Bumper Response') ylabel('Position, m') subplot(2,1,2) plot(t,v) ylabel('Speed, m/s') xlabel('Time, s') Command Window:
  • 19. Question 02: (Script File) %FAIQ ALI ME-22150 P=0:200; Q=1020*sqrt(P).*(1-0.01*sqrt(P)); plot(P,Q) title('Small Community Firefighting Water Needs') xlabel('Population,Thousands') ylabel('WaterDemand,gal/min') Command Window:
  • 20. LAB SESSION 07 Question 01: (Script File) %FAIQ ALI ME-22150 clc,clear for k=1:3 disp('For the Equation ax^2+bx+c') a=input('Enter a: '); b=input('Enter b: '); c=input('Enter c: '); D=b^2-4*a*c; if D<0 fprintf('n The equation has no real root.nn') elseif D==0 root=-b/(2*a); fprintf('n The Equation has One root, n') fprintf(' %.3fnn',root) else r1=(-b+sqrt(D))/(2*a); r2=(-b-sqrt(D))/(2*a); fprintf('n The Equation has two roots, n') fprintf(' %.3f and %.3fnn',r1,r2) end end
  • 21. Question 02: (Script File) %FAIQ ALI ME-22150 for k=1:2 gender=input('Please input your gender (male or female): ','s'); age=input('Please input your age: '); RHR=input('Please enter your resting heart rate: '); fit=input('Please enter your fitness level (low, medium, or high: ','s'); gender = lower(gender); fit = lower(fit); switch fit case 'low' INTEN=0.55; case 'medium' INTEN=0.65; case 'high' INTEN=0.8; end switch gender case 'male' THR=((220-age)-RHR)*INTEN+RHR; case 'female' THR=((206-0.88*age)-RHR)*INTEN+RHR; end fprintf('nThe recommended training heart rate is %.0fnn',THR); end Command Window:
  • 22. Question 03: (Script) %FAIQ ALI ME-22150 for j=1:2 W=input('Please input your weight in lb: '); h=input('Please input your height in in: '); BMI=703*W/h^2; if BMI<18.5 fprintf('nYour BMI value is %.1f, which classifies you as underweightnn',BMI) elseif BMI<25 fprintf('nYour BMI value is %.1f, which classifies you as normalnn', BMI) elseif BMI<30 fprintf('nYour BMI value is %.1f, which classifies you as overweightnn',BMI) else fprintf('nYour BMI value is %.1f, which classifies you as obesenn', BMI) end end Command Window:
  • 23. Question 04: (Script File) %FAIQ ALI ME-22150 for j=1:3 n(1:8)=0; cost=randi([1 5000],1,1)/100; fprintf('The total charge is $%.2fn',cost) pay=input('Please enter payment (1, 5, 10, 20, or 50): '); if pay<cost fprintf('Insufficient Paymentnn') 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>=.25 n(5)=n(5)+1; change=change-.25 end while change>=.10 n(6)=n(6)+1; change=change-.10; end if change>=.05; n(7)=1; change=change-.05; end change+.000001;
  • 24. while change>=.01 n(8)=n(8)+1; change=change-.01; end end fprintf('n $20 $10 $5 $1 $0 $0.25 $0.10 $0.05 $0.01n') fprintf(' %i',n) Command Window
  • 25. Question 05: (Script File) %FAIQ ALI ME-22150 for j=1:3 p=input('Please enter the pressure: '); old=input('Please enter the units (Pa, psi, atm, or torr): ','s'); new=input('Please enter the desired units (Pa, psi, atm, or 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%snn',pnew,pnew)
  • 27. Question 06: (Script File) %FAIQ ALI ME-22150 time=input('Enter the time of the call (day,evening,or night):','s'); duration=input('Enter the duration of the call in minutes: '); duration=ceil(duration); rate_day=0.10; rate_evening=0.04; rate_night=0.02; switch time case 'day' cost=duration*rate_day; case'evening' cost=duration*rate_evening; case 'night' cost=duration*rate_night; otherwise error('invalid time sepecified'); end if duration > 10 if duration <=30 cost=cost+1.00+(duration-10)*0.08; else cost=cost+1.00+20*0.08+(duration-30)*0.06; end end fprintf('The cost of the call is %.2fn',cost); Command Window:
  • 28. LAB SESSION 08 Question 01: (Script File) %FAIQ ALI ME-22150 V = [5, 17, -3, 8, 0, -7, 12, 15, 20, -6, 6, 4, -7, 16]; for i = 1:length(V) if V(i) > 0 && (mod(V(i), 3) == 0 || mod(V(i), 5) == 0) V(i) = V(i) * 2; end end j = 1; while j <= length(V) if V(j) < 0 && V(j) > -5 V(j) = V(j) ^ 3; j = j + 1; % Skip to next element end j = j + 1; end disp(V); Command Window:
  • 29. Question 04: (Script File) % FAIQ ALI ME-22150 x = 2; term = 1; sum = 1; n = 1; while abs(term) >= 0.0001 && n <= 30 term = term * x / n; sum = sum + term; n = n + 1; end if n > 30 && abs(term) >= 0.0001 disp('More than 30 terms are needed.'); else disp(['e^', num2str(x), ' = ', num2str(sum)]); end Command Window:
  • 30. Question 03 (Script File) % FAIQ ALI ME-22150 % Input parameters n = 4; % or n = 6 firstElement = 1; secondElement = 2; % Construct the matrix fibMatrix = zeros(n,n); fibMatrix(1, 1) = firstElement; fibMatrix(1, 2) = secondElement; for i = 2:n for j = 1:n-i+1 fibMatrix(i, j) = fibMatrix(i-1, j) + fibMatrix(i-1,j+1); end end disp(['Matrix of order ', num2str(n), ' with firsttwo elements:']) num2str(firstElement), ', ', num2str(secondElement)]); disp(fibMatrix); % Verify determinant is zero determinant = det(fibMatrix); disp(['Determinant of the matrix: ', num2str(determinant)]); Command Window
  • 31. Question 04: (Script File) %FAIQ ALI ME-22150 m_values = [5, 10, 20]; for m = m_values sum = 0; n = 0; while true term = (-1/3)^n / (2*n + 1); sum = sum + term; n = n + 1; if abs(term) < 1e-15 break; end end % Display the result and compare with ? disp(['For m = ', num2str(m)]); disp(['Result: ', num2str(sqrt(12)*sum)]); disp(['Comparison with pi: ', num2str(pi)]); disp(' '); end Command Window
  • 32. Question 05: (Script File) %FAIQ ALI ME-22150 m_values = [100, 100000, 1000000]; for m = m_values product = 1; n = 1; while true term = (2^(2*n))/(2^(2*n) - 1); product = product * term; n = n + 1; if n > m break; end end disp(['For m = ', num2str(m)]); disp(['Result: ', num2str(2*product)]); disp(['Comparison with pi: ', num2str(pi)]); disp('') end
  • 33. Question 06: (Script File) %FAIQ ALI ME-22150 scores = [73, 91, 37, 81, 63, 66, 50, 90, 75, 43, 88, 80, 79, 69, 26, 82, 89, 99, 71, 59]; sorted_scores = sort(scores, 'descend'); top_scores = sorted_scores(1:8); average = mean(top_scores); % Display the average disp(['Average of the top 8 scores: ', num2str(average)]); Command Window
  • 34. Question 07: (Script File) %FAIQ ALI ME-22150 x_degrees = input('Enter the angle in degrees: '); x_radians = deg2rad(x_degrees); term = x_radians; sum = term; n = 1; estimated_error = abs(term/sum); while estimated_error > 1e-5 term = (-1)^n * (x_radians^(2*n+1)) / factorial(2*n +1); sum = sum + term; n = n + 1; estimated_error = abs(term / sum); end disp(['sin(', num2str(x_degrees), ') = ', num2str(sum)]); disp(['Comparison with calculator: ',num2str(sin(x_radians))]); Command Window
  • 35. LAB SESSION 09 Question 01: (Script) % FAIQ ALI ME-22150 function [Smax,Smin] = princstress(Sxx, Syy, Sxy) %Calculates princstress, Pricipal Stress, using the 3 stress components Smax=((Sxx+Syy)/2)+(sqrt(((Sxx-Syy)/2)^2+(Sxy^2))); Smin=((Sxx+Syy)/2)-(sqrt(((Sxx-Syy)/2)^2+(Sxy^2))); fprintf('Maximum Principal Stress: %.4fn', Smax); fprintf('Minimum Principal Stress: %.4fn', Smin); end Command Window: a) Maximum Principal Stress: 177.8902 Minimum Principal Stress: -222.8902 ans = 177.8902 b) Maximum Principal Stress: 16.0605 Minimum Principal Stress: -17.0605 ans = 16.0605
  • 36. Question 02: (Script) %FAIQ ALI ME-22150 function ellipseplot(xc,yc,a,b) %ellipseplot calculates and plots the ellipse with xc center and yc center theta = linspace(0, 2*pi, 100); x = xc + a * cos(theta); y = yc + b * sin(theta); plot(x, y); xlabel('x'); ylabel('y'); title('Ellipse Plot'); end Command Window:
  • 37. Question 03: (Script) %FAIQ ALI ME-22150 function [HI] = HeatIn(T,R) %HeatIn calcualtes Heat index using Temperature and R humidity C1=-41.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; HIx=C1+C2*T+C3*R+C4*T*R+C5*(T^2)+C6*(R^2)+C7*(T^2)*R+C8*T*( R^ 2 )+C9*(T^2)*(R^2); HI=round(HIx); end Command Window:
  • 38. Question 04: (Script) %FAIQ ALI ME-22150 function [y] = fifthroot(P) % Function calculates the fifth root of the number P i = 1; E = 1; X(1) = P; while E > 0.00001 i = i + 1; X(i) = X(i-1) - ((X(i-1)^5 - P) / (5*(X(i-1))^4)); E = abs((X(i) - X(i-1)) / X(i-1)); e end y = X(i); end Command Window:
  • 39. LAB SESSION 10 Question 01: (Script) %FAIQ ALI ME-22150 disp('addition'); p1=[8 10 0 -5 13 -4 -2]; p2=[4 0 7 0 6]; p_add=p1+[0 0 p2]; disp(p_add) disp('subtraction'); p_subtract=p1-[0 0 p2]; disp(p_subtract); Command Window:
  • 40. Question 02: (Script) %FAIQ ALI ME-22150 disp('multiplication'); a1=[-2 0 3 4 0 -7 8]; a2=[5 0 -4 3 -5]; b=conv(a1,a2); disp(b) Command Window:
  • 41. Question 03: (Script) %FAIQ ALI ME-22150 R=9; V=500; h=9:-0.2:-9; % Part(a) p=[-1 -R R^2 R^3]; Vh=polyval(p,h)*pi/3; %Part(b) plot(h,Vh); xlabel('h (in.)'); ylabel('Volume (in^3)'); % Part (c) disp('Part (c)'); hV500=[-1 -R R^2 R^3-3*V/pi]; h500=roots(hV500); disp(h500); %Part(d) disp('Part (d)'); Vpd=polyder(p); rVmax=roots(Vpd); disp(rVmax); Vmax=polyval(p,rVmax(2))*pi/3; COMMAND WINDOW:
  • 42. Question 04: (Script) %FAIQ ALI ME-22150 p1=[1 0]; p2=[1 5]; p3=[1 10]; p12=conv(p1,p2); p=conv(p12,p3); n=length(p); p(n)=p(n)-10098; s=roots(p) COMMAND WINDOW
  • 43. Question 05: (Script) %FAIQ ALI ME-22150 % Find the cube root of 13,440 cube_root = nthroot(13440, 3); % Round the cube root to the nearest integer integer_root = round(cube_root); % Calculate the four consecutive integers integers = integer_root - 1 : integer_root + 2; % Display the consecutive integers disp(integers); COMMAND WINDOW:
  • 44. LAB SESSION 10 Question 01: (Script) % FAIQ ALI ME-22150 T = [-20, 0, 20, 40, 60, 80, 100, 120]; d = [4, 0.38, 0.095, 0.032, 0.015, 0.0078, 0.0045, 0.0032]; % Fit a quadratic equation using polyfit pf=polyfit(T,log(d),4); % Estimate viscosity at 150 degrees Celsius T_150=exp(polyval(pf,150)); % Plotting x_cal=-20:.01:120; y_cal=exp(polyval(pf,x_cal)); plot(T,d,'o',x_cal,y_cal,'r-', 'LineWidth', 1.5) xlabel('Temperature (K)'); ylabel('Viscosity (Ns/m^2)'); title('Viscosity of Oil'); legend('Data Points', 'Fitted Equation'); grid on fprintf('Estimated viscosity at 150 °C: %.4f *10Nsm^2n',T_150) COMMAND WINDOW:
  • 45. Question 02: (Script) h_ft = [-1000, 0, 3000, 8000, 15000, 22000, 28000]; % Altitude in feet T_F = [213.9, 212, 206.2, 196.2, 184.4, 172.6, 163.1]; % Boiling temperature in Fahrenheit % Convert altitude from feet to meters h_m = h_ft * 0.3048; % Fit a linear equation using polyfit coeff = polyfit(h_m, T_F,2); % Calculate boiling temperature at 5,000 m h_5000 = 5000; T_5000_F = polyval(coeff,h_5000); % Plotting figure; h_plot = linspace(min(h_m), max(h_m), 100); T_plot = polyval(coeff,h_plot); plot(h_m, T_F, 'bo',h_plot, T_plot, 'r-', 'LineWidth', 1.5); % Data points xlabel('Altitude (m)'); ylabel('Boiling Temperature (°C)'); title('Boiling Temperature of Water at Different Altitudes'); legend('Data Points', 'Fitted Equation'); fprintf('Boiling temperature at 5,000 m is %.2f °Fn',T_5000_F); COMMAND WINDOW:
  • 46. Question 03: (Script) %FAIQ ALI ME-22150 t = [0, 1, 3, 4, 6, 7, 9]; % Time in hours NB = [500, 600, 1000, 1400, 2100, 2700, 4100]; % Fit an exponential function using the polyfit coeff = polyfit(t, log(NB),6); % Estimate the number of bacteria after 5 hours t_5 = 5; NB_5 = exp(polyval(coeff,t_5)); % Plotting t_plot = linspace(min(t), max(t), 1000); NB_plot = exp(polyval(coeff,t_plot)); plot(t, NB, 'bo',t_plot, NB_plot, 'r-', 'LineWidth',1.5); xlabel('Time (hours)'); ylabel('Number of Bacteria'); title('Growth of Bacteria over Time'); legend('Data Points', 'Fitted Equation'); % Display estimated number of bacteria after 5 hours fprintf('Estimated number of bacteria after 5 hours: %.2fn', NB_5); COMMAND WINDOW: