Download (right-click, save target as ...) this page as a jupyterlab notebook from: Lab6-HW
LAST NAME, FIRST NAME
R00000000
ENGR 1330 Laboratory 6 - Homework
# Preamble script block to identify host, user, and kernel
import sys
! hostname
! whoami
print(sys.executable)
print(sys.version)
print(sys.version_info)
atomickitty sensei /opt/jupyterhub/bin/python3 3.8.10 (default, Jun 2 2021, 10:49:15) [GCC 9.4.0] sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0)
Make a function that cubes its input:
$$ f(x) = x^3 $$and test it for the following values of x:
def xcube(input_value):
output_value = pow(input_value,3)
return output_value
print(xcube(-1))
-1
print(xcube(0.0))
0.0
print(xcube(1.0))
1.0
print(xcube(2.0))
8.0
print(xcube(3.0))
27.0
Generate two lists:
x
ranging from 0 to 9 in steps of 1f(x)
from your function in Exercise 1Use the plotAline()
function (below) to create a plot of
for x raging from 0 to 9 (inclusive) in steps of 1.
Label the plot and the plot axes.
A wrapper script is included below that needs completion to work and draw the plot.
def plotAline(list1,list2,strx,stry,strtitle): # plot list1 on x, list2 on y, xlabel, ylabel, title
import matplotlib.pyplot # import the plotting library from matplotlib.pyplot
matplotlib.pyplot.plot( list1, list2, color ='green', marker ='o', linestyle ='solid') # create a line chart, years on x-axis, gdp on y-axis
matplotlib.pyplot.title(strtitle)# add a title
matplotlib.pyplot.ylabel(stry)# add a label to the x and y-axes
matplotlib.pyplot.xlabel(strx)
matplotlib.pyplot.show() # display the plot
return #null return
# wrapper script
x = [i for i in range(10)] # define two lists
y = [pow(i,3) for i in range(10)]
plotAline(x,y,"x"," x^3","Plot of y=x^3")
Modify the wrapper script for the plotAline()
function to create a plot of
$$ x = 16sin^3(t) $$
$$ y = 13cos(t) - 5cos(2t) - 2cos(3t) - cos(4t) $$
for t raging from [0,2$\Pi$] (inclusive).
Label the plot and the plot axes.
# wrapper script
import math
t = [(1/50)*math.pi*i for i in range(101)] # build parameter list
x = [16*pow(math.sin(t[i]),3) for i in range(101)] # define two lists
y = [13*math.cos(t[i])-5*math.cos(2*t[i])-2*math.cos(3*t[i])-math.cos(4*t[i]) for i in range(101)]
plotAline(x,y,"x"," y","I heart U")