0% found this document useful (0 votes)
324 views1 page

Tutorial 3 - Functions

This document discusses writing MATLAB functions for various mathematical formulas and geometric shapes. It contains 3 sections: 1) Write a function to calculate y = -0.2x^4 + e^-0.5x x^3 + 7x^2 for a vector input x. 2) Write a function to calculate body fat percentage given mass, height, age, and gender. 3) Create anonymous functions to calculate the volume and surface area of a torus given inner and outer radii, and plot these versus the inner radius.

Uploaded by

Darksky Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
324 views1 page

Tutorial 3 - Functions

This document discusses writing MATLAB functions for various mathematical formulas and geometric shapes. It contains 3 sections: 1) Write a function to calculate y = -0.2x^4 + e^-0.5x x^3 + 7x^2 for a vector input x. 2) Write a function to calculate body fat percentage given mass, height, age, and gender. 3) Create anonymous functions to calculate the volume and surface area of a torus given inner and outer radii, and plot these versus the inner radius.

Uploaded by

Darksky Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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 persons 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.

You might also like