Sale!

COMP 1012– Assignment 3 and Assignment 4

$30.00 $18.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (4 votes)

Outcomes
Numpy
Functions
Description
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 can’t 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.
8/9/2020 comp1012-a3-template_updated
file:///C:/Users/ngocp/OneDrive/Documents/Github/COMP1012/Assignments/Assignment3&4/comp1012-a3 a4.html 2/5
To approximate the length of the curve, we can consider the curve between two neighboring points
is a straight line. For example, we can consider and a straight line and then and a straight
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
is . The length will be . So, if we have points, the length of the
curve can be approximated by:
Where indicates the Euclidean distance between two points. The Euclidean distance can be
calculated using the following formula:
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.
8/9/2020 comp1012-a3-template_updated
file:///C:/Users/ngocp/OneDrive/Documents/Github/COMP1012/Assignments/Assignment3&4/comp1012-a3 a4.html 3/5
The surface area of a frustum: . This equation can be rewritten as:
Here, s are the points that we used when calculating the length.
What to do:
In your program, you need to implement the following functions.
8/9/2020 comp1012-a3-template_updated
file:///C:/Users/ngocp/OneDrive/Documents/Github/COMP1012/Assignments/Assignment3&4/comp1012-a3 a4.html 4/5
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:
for i in range(1, 100, 10):


start/end |length (m)|area (m^2)
———–+———-+———-
1 … 10 |1.629E+02 |8.250E+04
———–+———-+———-
11 … 20 |8.383E+02 |3.318E+06
———–+———-+———-
8/9/2020 comp1012-a3-template_updated
file:///C:/Users/ngocp/OneDrive/Documents/Github/COMP1012/Assignments/Assignment3&4/comp1012-a3 a4.html 5/5
“Programmed by…”
Use the following code snippet at the end of your script to print out the time and end of processing
message:
Handing in
An assignment submission area has been created for Assignment 3. Click on the “Assessments”
menu, then click on “Assignments”.
The only thing you’re required to turn in for this assignment is the .py script that you create. Please
name your script file with the following convention:
[tutorial.math.lamar.edu/Classes/CalcII/SurfaceArea.aspx]:
21 … 30 |1.827E+03 |2.417E+07
———–+———-+———-
31 … 40 |3.046E+03 |9.205E+07
———–+———-+———-
41 … 50 |4.458E+03 |2.514E+08
———–+———-+———-
51 … 60 |6.040E+03 |5.619E+08
———–+———-+———-
61 … 70 |7.775E+03 |1.098E+09
———–+———-+———-
71 … 80 |9.650E+03 |1.950E+09
———–+———-+———-
81 … 90 |1.166E+04 |3.222E+09
———–+———-+———-
91 … 100 |1.378E+04 |5.034E+09
———–+———-+———-
Programmed By Instructors
University of Manitoba
Computer Science
import time
print (“\nProgrammed by ******YOU******”)
print (“Date: ” + time.ctime())
print (“End of processing”)
FirstnameLastnameA3Q1.py