Question

In: Computer Science

Assume there is a function called frustumArea that has three input arguments and returns the area...

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.

Solutions

Expert Solution

####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)

  


Related Solutions

In Python Create a function called ℎ?????. The function has as arguments a list called ??????...
In Python Create a function called ℎ?????. The function has as arguments a list called ?????? and a list call center. • List ?????? contains lists that represent points. o For example, if ?????? = [[4,2], [3,2], [6,1]], the list [4,2] represents the point with coordinate ? at 4 and y coordinate at 2, and so on for the other lists. Assume that all lists within points contain two numbers (that is, they have x, y coordinates). • List ??????...
Write a function called draw_card. It takes no arguments and returns an integer representing the value...
Write a function called draw_card. It takes no arguments and returns an integer representing the value of a blackjack card drawn from a deck. Get a random integer in the range 1 to 13, inclusive. If the integer is a 1, print "Ace is drawn" and return 1. If the integer is between 2 and 10, call it x, print "<x> is drawn" and return x (print the number, not the string literal "<x>"). If the number is 11, 12,...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a weighted sum of that numbers digits. The last digit of the number (the ones digit) has a weight of 1, so should be added to the sum "as is". The second from last digit (the tens digit) has a weight of 2, and so should be multiplied by 2 then added to the sum. The third from last digit should be multiplied by 1...
Write a function called alternate that takes two positive integers, n and m, as input arguments...
Write a function called alternate that takes two positive integers, n and m, as input arguments (the function does not have to check the format of the input) and returns one matrix as an output argument. Each element of the n-by-m output matrix for which the sum of its indices is even is 1. All other elements are zero. For example, here is an example run: >> alternate(4,5) ans = 1 0 1 0 1 0 1 0 1 0...
Write python 3 code to define a function that uses three arguments, and returns a result....
Write python 3 code to define a function that uses three arguments, and returns a result. The function returns True if the first argument is more than or equal to the second argument and less than or equal to the third argument, otherwise it returns False. Write a python 3 code for function main, that does the following: creates a variable and assign it the value True. uses a while loop which runs as long as the variable of the...
Function named FunCount takes three arguments- C, an integer representing the count of elements in input...
Function named FunCount takes three arguments- C, an integer representing the count of elements in input list IP- input list of positive integers. Item- an integer value. Function FunCount returns an integer representing the count of all the elements of List that are equal to the given integer value Key. Example: Don’t take these values in program, take all inputs from user C = 9, IP= [1,1,4,2,2,3,4,1,2], Item = 2 function will return 3 IN C PROGRAMMING
2 Write a function named equivalentArrays that has two array arguments and returns 1 if the...
2 Write a function named equivalentArrays that has two array arguments and returns 1 if the two arrays contain the same values (but not necessarily in the same order), otherwise it returns 0. Your solution must not sort either array or a copy of either array! Also you must not modify either array, i.e., the values in the arrays upon return from the function must be the same as when the function was called. Note that the arrays do not...
Write a function that will receive two input arguments that is the height in inches (in.)...
Write a function that will receive two input arguments that is the height in inches (in.) and the weight in pounds (lb) of a person and return two output arguments that is the height in meters (m) and mass in kilograms (kg). Determine in SI units the height and mass of a 5 ft.15 in. person who weight 180 lb. Determine your own height and weight in SI units. Note: 1 meter = 39.3701 inch, 1 foot = 12 inches,...
Write code to define a function named mymath. The function has three arguments in the following...
Write code to define a function named mymath. The function has three arguments in the following order: Boolean, Integer, and Integer. It returns an Integer. The function will return a value as follows: 1. If the Boolean variable is True, the function returns the sum of the two integers. 2. If the Boolean is False, then the function returns the value of the first integer - the value of the second Integer.
Write a function that takes a number as input, and returns the character A if the...
Write a function that takes a number as input, and returns the character A if the input is 90 and above, B if it’s 80 and above but less than 90, C if it’s at least 70 but less than 80, D if it’s at least 60 but less than 70, and F if it’s less than 60. If the input is not a number or is negative, the function should exit 1 with an error (by calling the Matlab...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT