Matlab-Ex (Chp#6) .
Matlab-Ex (Chp#6) .
Chp#6.
Exercise.
1.
Here's the MATLAB function:
Code snippet
function [cm, kg] = STtOSI(in, lb)
% Convert height in inches to centimeters
cm = in * 2.54;
% Convert weight in pounds to kilograms
kg = lb * 0.453592;
end
a) To determine the height and mass of a 5 ft. 10 in. person
who weighs 175 lb:
Code snippet
For example, if you are 6 ft. 2 in. (74 inches) tall and weigh
185 lb, you would type:
Code snippet
[cm, kg] = STtOSI(74, 185)
This will output your height in centimeters and weight in
kilograms.
------------------------------------------------------------------------------------
2.
------------------------------------------------------------------------------------
3.
polarplot(theta_values, r_values);
title('Polar Plot of r(theta) = 2*(1.1 -
(sin(theta))^2)');
grid on;
------------------------------------------------------------------------------------
4.
5.
------------------------------------------------------------------------------------
6.
------------------------------------------------------------------------------------
7.
8.
----------------------------------------------------------------------------------
9.
10.
g = homework_weight * mean(homework_grades, 2)
+ ...
2 * midterm_weight * mean(midterm_grades,
2) + ...
final_weight * final_exam_grades;
end
a) Calculating the grade of one student in the Command
Window:
Code snippet
grades = [10, 5, 8, 7, 9, 75, 87, 69];
final_grade = fgrade(grades)
disp('The final grade is: ', final_grade)
b) Script file to calculate grades for multiple students:
Code snippet
% Ask the user to enter the grades
num_students = input('Enter the number of
students: ');
grades = zeros(num_students, 8);
for i = 1:num_students
disp('Enter grades for student ', i);
grades(i, :) = input('Enter grades (homeworks,
midterms, final): ');
end
11.
13.
I = Ibeam(w, h, t);
disp('Moment of inertia of the I-beam: ', I, '
mm^4')
14.
------------------------------------------------------------------------------------
15.
16.