In: Computer Science
Assume there is a function called frustumArea that has three input arguments and returns the area of a frustum: area = frustumArea( height, majRadius, minRadius ). When the major and minor radii of a frustum are equal, the frustum is a cylinder. Write a new function named cylinderArea that uses the frustumArea function to compute and return the area of a cylinder. Do this for both Python and Matlab.
####below is the python code
# while pasting indentations\tabs may get disturbed, please refer pic for correct tabs
import math
def frustumArea( height, majRadius, minRadius ):
r1=majRadius;
r2=minRadius;
h=height;
area= math.pi*(r1**2+ r2**2+(r1+r2)*((r1-r2)**2+h**2)**0.5)
return area
def cylinderArea(height,radius):
area=frustumArea(height,radius,radius)
return area
print(cylinderArea(1,1))
print(frustumArea(1,1,1))
%%%%%%%%below is the matlab code
function area= frustumArea( height, majRadius, minRadius )
r1=majRadius;
r2=minRadius;
h=height;
area= pi*(r1^2+ r2^2+(r1+r2)*((r1-r2)^2+h^2)^0.5);
end
function area=cylinderArea(height,radius)
area=frustumArea(height,radius,radius);
end
cylinderArea(1,1)
frustumArea(1,1,1)