You are on page 1of 1

Engineering Software & Applications Tutorials Chapter 3 – Functions

1. Write a user user-defined defined MATLAB function for the following math function:

y = −0.2 x 4 + e −0.5 x x3 + 7 x 2
The input to the function is x and the output is y. Write the function such that x can be a vector. a) Use the function to calculate y(-2.5) and y(3) b) Use the function to make a plot of the function y(x) for -3 ≤ x ≤ 4 2. The body fat percentage (BFP) of a person can be estimated by the formula

BFP = 1.2 × BMI + 0.23 × Age − 10.8 × Gender − 0.54
m , in which m is the mass in H2

Where BMI is the body mass Index, given by BMI = 10002.5

kilogrammes and H is the height in centimetres, Age is the person’s age, and Gender = 1 for a male and 0 for a female. Write a MATLAB user user-defined defined function that calcul calculates ates the body fat percentage. For the function name and arguments use BFP = BodyFat(m, h, age, gen). The input arguments are the mass, height, age, and gender respectively. The output argument is the BFP value. Use the function to calculate the body fat pe percentage rcentage of: a) A 35-years-old, old, 188 cm tall, 99 kg male. b) A 22-years-old, old, 170 cm tall, 61 kg female. 3. A torus is shaped like a doughnut. doughnut. If its inner radius is a and its outer radius is b, its volume and surface area are given by:

1 2 v = π 2 (a + b) )(b − a ) , A = π 2 ( b2 − a 2 ) 4

a) Create two anonymous functions that computes V and A from the arguments a and b. b) Suppose that the outer radius is constrained to be 2 cm greater than the inner radius. Write a script file that uses your anonymous functions to plot A and V versus a for 0.25 ≤ a ≤ 4 cm.