CoCalc Shared FilesLab 1 / lab 1 further exercises.sagews
Author: Kelly Truong
Views : 38
#lab 1 further exercises
#1 Plot the function f(x) = x^2 for values of x ranging between -5 and 5
plot(x^2, (x,-5,5))

#2 Plot the function f(x) = x^3 for values of x ranging between -5 and 5
plot(x^3, (-5,5))

#3. Overlay these plots.
plot(x^2, (x,-5,5)) + plot(x^3, (-5,5))

#44. Complete the following interactive so that it plots the function f(x) = ax3 with a plotting range of 0 to 5, so a can vary from -10 to 10.
@interact
def foo(a=(-10,10)):
p= plot(a*x^3,(x,0,5))
show(p)

#5
@interact
def expnt(n=(0,6)):
p= plot(x^n, (x,-5,5), ymin=-5^4,ymax=5^4)
show(p)

#6
#@interact     syntax that allows for interactive graphs
#def expnt(n=(0,6)):     defines exponnet as an adjustable variable ranging from 0 to 6
#   p= plot(x^n, (x,-5,5), ymin=-5^4,ymax=5^4)    makes variable p a plot for the graph x^n, with x values from -5 to 5, and y values from -5^4 to 5^4
#    show(p)     shows the intereactive graph

#7. What does “calling a function” mean? What are arguments?
#it means to use a function with the input you give. Arguments are the function inputs

#8 When is it useful or necessary to assign a value to a variable? How do you  do this?
#it is useful to assign a value to a variable to keep track of data if you're reusing it and want to label it. you do this by using the = sign to assign a value to a varaible name

#9 Briefly explain why it might be a good idea to use descriptive variable and function names in your code.
#so you can easily distinguish and keep track of variables and functions so you know when to use them