if-end statementif-else-end statementif-elseif-else-end statementProblem 9 Number (10/10)
Problem 12 Quadroots (15/15)
Problem 26 BMI (14/15) Did not round BMI to one decimal place
Problem 35 Grades (20/20)
Problem 34 Cam (16/20) Did not save a png of the plot. Did not successfully run, calculation error; missing math operator between parentheses
Click on + New then the File pulldown to create a new Octave (.m) script files for each of the following problems from Chapter 6. Include comments in each with your name and the problem number. Use the names given below with your FerrisID. Be sure to follow any additional instructions given as well as those in the textbook.
number9_FerrisID.m (10 points): (use a while-end loop and if-else commands)quadroots_FerrisID.m (15 points)bmi_FerrisID.m (15 points)grades_FerrisID.m (20 points)cam_FerrisID.m (20 points)Include a disp command near the beginning of each script that states the problem number. Also, clear all variables and clear the screen at the beginning of each script.
Since some programs require the use of the input command and the Jupyter notebook interface does not support this command you will need to start an Octave session by clicking on "Octave Terminal.term" in the assignment folder in order to run your programs.
After testing and degbugging all of the programs start logging/recording your session by typing diary lab16_practice_FerrisID.txt using your FerrisID, i.e. diary lab16_practice_bradyb.txt
Create the comment % MECH 322: Lab 16 - Conditional Practice
Create a comment line with your name
Run each of the scripts by typing the script name without the .m extension. Insert a few blank lines between each script execution by hitting the return key
Issue the command diary off to stop recording your session
Your diary file lab16_practice_FerrisID.txt and the six script files you created will be automatically collected for grading after the due date.
The author apparently misread his Kinematics textbook or had a bad one. Please use the following formulas instead.
$$\begin{align} y&=\frac{6}{\pi}\left[2\theta-0.5\sin{4\theta}\right] &0\leq\theta\leq\pi/2\\ \\y&=6 &\pi/2 \leq\theta\leq2\pi/3\\ \\y&=3+1.5\left[1+\cos{\left(1.5\theta-\pi\right)}\right] &2\pi/3\leq\theta\leq4\pi/3\\ \\y&=3 &4\pi/3 \leq\theta\leq3\pi/2\\ \\y&=3-6\left(\frac{2\theta-3\pi}{\pi}\right)^2 &3\pi/2\leq\theta\leq 7\pi/4\\ \\y&=6\left(1-\frac{2\theta-3\pi}{\pi}\right)^2 &7\pi/4\leq\theta\leq 2\pi \end{align}$$% Problem 35 - Grades
% Chase Benson
Q=input('Enter 6 quiz scores in a vector surrounded by [ ]:');
M=input('Enter 3 midterm grades in a vector:');
F=input('Enter final exam score:');
Qavg=sort(Q)
Q(1)=[];
Qavg=mean(Q)/10;
Qweight=Qavg*.3;
Mavg=mean(M)/100;
F=F/100;
if Mavg>F
Mweight=Mavg*.5;
Fweight=F*.2;
else
Mweight=Mavg*.2;
Fweight=F*.5;
end
grade=(Qweight+Mweight+Fweight)*100;
if grade < 60
letter="an E";
elseif grade < 70
letter="a D";
elseif grade < 80
letter="a C";
elseif grade < 90
letter="a B";
else
letter="an A";
end
printf('The students overall score is %.0f and they received an %s\n',grade,letter)
% Problem 9 - number 9
% Chase Benson
clear
i=0;
s=0;
while s<=120
i=i+1;
if rem(i,2)==0 && rem(i,13)==0 && rem(i,16)==0
s=sqrt(i);
end
end
fprintf('The required number is: %i\n',i)
% Problem 12 - Quad roots
% Chase Benson
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('\nThe equation has no real roots.\n\n')
elseif D==0
root=-b/(2*a);
fprintf('\nThe equation has one root.\n\n')
fprintf(' %.3f\n\n',root)
else
r1=(-b+sqrt(D))/(2*a);
r2=(-b-sqrt(D))/(2*a);
fprintf('\nThe equation has two roots.\n\n')
fprintf(' %.3f and %.3f\n\n',r1,r2)
end
end
% Problem 26 - BMI
% Chase Benson
clear
for j=1:2
W=input('Input weight in lb: ');
h=input('Input height in in: ');
BMI=703*W/h^2;
if BMI<18.5
fprintf('BMI value %.1f, which means underweight\n\n',BMI)
elseif BMI<25
fprintf('BMI value %.1f, which means normal\n\n',BMI)
elseif BMI<30
fprintf('BMI value %.1f, which means overweight\n\n',BMI)
else
fprintf('BMI value %.1f, which means obese\n\n',BMI)
end
end
% Problem 34 - Cam
% Chase Benson
clear
theta=linspace(0,2*pi,100);
for i=1:100
if theta(i)<=pi/2
y(i)=6*(2*theta(i)-0.5*sin(theta(i)))/pi;
elseif theta(i)<=2*pi/3
y(i)=6;
elseif theta(i)<=4*pi/3
y(i)=6-3*(1-0.5*cos(3*(theta(i)-2*pi/3)));
elseif theta(i)<=3*pi/2
y(i)=3;
elseif theta(i)<=7*pi/4
y(i)=3-1.5*((theta(i)-3*pi/2)(pi/4))^2;
else
y(i)=0.75-0.75*(1-(theta(i)-7*pi/4)/(pi/4))^2;
end
end
plot(theta,y)
xlabel('rotation angle, rad')
ylabel('follower displacement, cm')