Computational Biomechanics and Rehabilitation Lab # 2
Computational Biomechanics and Rehabilitation Lab # 2
Lab # 2
1. Experiment in the Command Window, with using the fprintf function for real
numbers. Make a note of what happens for each. Use fprintf to print the real
number 12345.6789:
2. Experiment in the Command Window, with using the fprintf function for
integers. Make a note of what happens for each. Use fprintf to print the integer
12345:
b. in a field width of 5
c. in a field width of 8
d. in a field width of 3
x = 12.34;
y = 4.56;
Then fill in the fprintf statements using these variables that will accomplish the
following:
>>fprintf(
x is 12.340
>>fprintf(
x is 12
>>fprintf(
y is 4.6
>>fprintf(
y is 4.6 !
5. Write an input statement that will prompt the user for a real number, and store
it in a variable. Then use the fprintf function to print the value of this variable
using two decimal places.
6. The Body Mass Index (BMI) for a person is defined, using US units, as
BMI = 703*weight/height^2
Where the weight is in pounds and the height is in total inches. Write a function
called findbmi that would receive the weight and height as input arguments, and
would return the BMI. For example, to find the BMI for a person who weight 170
pounds and is 5’11” tall (71 inches), here are two examples of function calls:
>> findbmi(170,71)
ans =
23.7076
>>bmi = findbmi(170,71)
bmi =
23.7076
7. Create a script, temp_FC.m, that would prompt the user for a temperature, and
then ‘F’ or ‘C’, and store both inputs in variables. For example, when executed it
would look like this (assuming the user enters 85 and then F):
Enter the temperature: 85
Is that F or C?: F
8. For a project, some students are designing a device that will monitor a person’s
heart rate while on a treadmill. The device will let the subject know when the
target heart rate has been reached. A simple calculation of the target heart rate
(THR) for a moderately active person is
THR = (220-A)*0.6
where A is the person’s age. Write a function that will calculate and return the
THR.
9. If the length of two sides of a triangle and the angle between them are known,
the length of the third side can be calculated. Given the lengths of two sides (b
and c) or a triangle, and the angle between them (theta) in degrees, the third
side, a, can be calculated as:
A^2=b^2+c ^2-2bccos(theta)
Write a script thirdside that will prompt the user and read in values for b,c, and
theta (in degrees), and then calculate and print the value of a with three decimal
places. (Note: to convert an angle from degrees to radians, multiply the angle by
pi/180.)
The format of the output from the script should look like this:
>>thirdside
10. Prompt the user for the number of rows and columns of a matrix, create a matrix
with that many rows and columns of random numbers, and write it to a file.
11. a). Write a script file that calculates a damped sinusoidal waveform from ome
time data (you create). Use this as position data and calculate velocity and
acceleration using the diff function
Where
x = displacement
A= Amplitude
e = exponential (uses MATLAB function exp)
c = damping factor
t = time
f = frequency
b). Once calculated, plot the data in a 3x1 subplot so that position is on top, velocity
is in the middle, and acceleration is at the bottom. Be sure to include X and Y
labels on your plot.
c). Write a script file to save your data array in the form of
12. The sales (in billions) for two separate divisions of the XYZ Corporation for each
of the four quarters of 2007 are stored in a file called salefigs.dat:
a) Create this file (just type the numbers in the editor, and Save as salesfigs.dat).
ii) Plot Sales(billions) vs Quarter for each of the two divisions on the same
graph. Use o’s for Division 1 and +’s for Division 2. Label the x axis: Quarter,
the y axis: Sales (billions) and title: XYZ Corporation Sales: 2007. Include a
legend. Save the figure.