3 Area of a circle
In MATLAB, open the file circleArea.m
. This file contains a user-defined function that when completed returns the area of a circle having radius r.
Complete the function remembering to save the file every time that you edit it.
Recall that the area of circle is given by \(A = \pi r^2\).
3.1 Using circleArea.m
Test your function by typing the following in the MATLAB Command Window:
radius = 2.5;
a = circleArea(radius)
A correct function would cause the value 19.6350
to be output. If the correct value is not output, review your function and correct any errors that you find.
Test your function using different values for the radius; for example, type following statements in the MATLAB Command Window and verify that the outputs are correct:
circleArea(0)
circleArea(1)
circleArea(10)
3.2 Solve a simple problem using circleArea.m
An extra large pizza from Pizza Pizza has a diameter of \(0.4064\) meters (\(16\) inches) and costs $16.50. What is the cost of \(1\) square meter of pizza?
In MATLAB, open the script file called pizza.m
. Edit the script so that solves the above problem. Your script should use the function circleArea
that you created. Your script should store the cost per square meter in a variable named cost
.
Don’t forget to save your script every time that you edit it. Run your script by typing the following in the MATLAB Command Window:
pizza