In this assignment, you are going to calculate the length and surface area of a solid generated by a function.
You should use numpy where possible to do all the calculation. You also need to write the code in a numpy way (vectorization) which means you should not use loops if it is possible to write the program without using loops with numpy and you should use numpy arrays instead of a lists.
You need to follow the programming standards for this assignment. You will find more about programming standards on umlearn. Please go to the course page >> Content >> Additional Files >> Programming Standards.pdf
You cant use any libraries except time, numpy.
Question 1: Required
In this assignment, we are going to find the length and area under a curve. The curve that you will consider in this assignment is given by the (single variable) function . So for each value of , we will get a corresponding y value. For example, If we have values of , we will get values for . Now, if we plot these values, we will get a figure like the one we showed here.
line and so on. As the two neighboring points are straight line, we need to calculate the Euclidean distance between the two neighboring points and then take the summation of those distances. For example, suppose the Euclidean distance between and is , p1 and is , and and
. So, if we have points, the length of the
indicates the Euclidean distance between two points. The Euclidean distance can be
The surface area of the solid obtained when you revolve the curve around the -axis can be approximated in a way that is similar to the way we approximated the length of the curve. We can approximate the surface area of a small part of the solid and then take the summation of those small parts to finally get the approximate surface area. This can be compared to [frustums]
[tutorial.math.lamar.edu/Classes/CalcII/SurfaceArea.aspx]. Frustums look like the figure below.
What to do:
In your program, you need to implement the following functions. generatePoints():
This function will generate points using arange function where is the start and is the end and is the step.
evalFunction():
This function takes one parameter as input. The parameter is an array of numbers. It implements the curve function mentioned in the description and returns the array. calculateSegmentDists(xx, yy):
This function takes two numpy array as input. The values in the array indicate axis and values in array indicates axis. It then returns the distances between each segment as an array. Here, the
segment means the Euclidean distance between the neighboring points.
calculateCurveLen(segDists):
This function takes segment distances as input and returns the curve length. calculateSurfaceArea(segDists, y):
This function takes segment distances and functional values given by as input and return the surface area for the solid. main():
The program will begin from this function. In this function, you need to use a for loop that starts at 1 and ends at 100 with step 10. Inside the for loop, you need to call the generatePoints function. The first parameter of generatePoints will be the value of for loop variable. For example, if we write:
here, i is the for loop variable. The second parameter of generatePoints function will be the value of for loop variable, i + 10 and you can set the third parameter, interval = 1. Then you need to call other functions inside the for loop to get surface areas and length of the curve for each iteration. For example, if the for loop iterates times, you will get lengths and areas. See sample output for clarification. You also need to print the values. printValues(starts, ends, lengths, areas):
This function takes a list of start points, end points, lengths and areas as input and show them in the output screen as given below.
Sample output:
Programmed by
Use the following code snippet at the end of your script to print out the time and end of processing message:
Reviews
There are no reviews yet.