CoCalc Shared FilesLab 5 / Lab5-turnin.sagews
Author: Nathaniel Song
Views : 43
# Lab 5:

# Name: Nathaniel Song
# I worked on this code with:

# Please do all of your work for this week's lab in this worksheet. If
# you wish to create other worksheets for scratch work, you can, but
# this is the one that will be graded. You do not need to do anything
# to turn in your lab. It will be collected by your TA at the beginning
# of (or right before) next week’s lab.

# Be sure to clearly label which question you are answering as you go and to

#1
%auto
typeset_mode(True, display=False)
def weird_function():
pieces = [sin(x), cos(x), arctan(x), ln(x), sqrt(x), exp(x)]
f(x)=prod([choice(pieces) for i in range(5)]) + prod([choice(pieces) for i in range(5)])
return f
h(x)=weird_function()

#2
(h(5.5)-h(3.5))/(5.5-3.5)

$162.643088454926$
#3
deltax=[1,.1,.01,.001]
vals=[]
for y in deltax:
p=3.5
a=(h(p+y)-h(p))/y
vals.append(a)
vals

[$-63.7603199280383$, $19.0546752598732$, $26.5383438390145$, $27.2393446152108$]
#4
p=2
vals

[$-63.7603199280383$, $19.0546752598732$, $26.5383438390145$, $27.2393446152108$]
#5
def function(p):
f(t)=1000*t^2
deltax=[1,.1,.01,.001]
vals=[p]
for y in deltax:
b=((p+y)-p)/y
vals.append(b)
return vals
function(1)

[$1$, $1$, $1.00000000000000$, $1.00000000000000$, $0.999999999999890$]
#6
def function(p):
f(t)=1000000*t^2
deltax=[1,.1,.01,.001]
vals=[p]
for y in deltax:
b=((p+y)-p)/y
vals.append(b)
return vals
function(1)

[$1$, $1$, $1.00000000000000$, $1.00000000000000$, $0.999999999999890$]
#7
#Limits are necessary when computing derivatives because that is what allows the approximation to be as accurate to zero as possible without actually hitting zero
#8
(x^5)/(x^3)
x^2
#9
type(x)
#10
factor(x^2 + 7*x + 6)

$x^{2}$
$x^{2}$
<type 'sage.symbolic.expression.Expression'>
${\left(x + 6\right)} {\left(x + 1\right)}$
#11
var("k")
factor(k^2 - 5*k + 6)

$k$
${\left(k - 2\right)} {\left(k - 3\right)}$
#12
var("n")
f(x)=2^n
plot(f(n),(n,-10,10))

$n$
#13
#because x is defined as a number and not a variable, so y will then become a result of the funtion
#14
i(x)=16*x^2
plot(i(x),(x,0,5)) + point([1,16], color="red",size=40)

#15
plots=[]
xmax=[5,3,2,1,.25]
for n in xmax:
p=plot(i(x),(x,0,5)) + point([1,16], color="red",size=40)
plots.append(p)
animate(plots)

#16
var("n")
@interact
def graph(n=(1.1,10)):
l=16*x^2
slope=(l(n)-16)/(n-1)
m=(slope*(x-n))+l(n)
n=plot(16*x^2,(x,0,10))+ plot(m, (x,0,10),ymin=0 ) + point([1,16], color="red", size=40) + point([n,(l(n))], color="red", size=40)
show(n)
#as the movable point approaches the fixed one, the approximation of the curve at the point (1,16) get more accurate

n
#17
var("n")
@interact
def graph(n=(1.1,10)):
l=16*x^2
slope=(l(n)-16)/(n-1)
m=(slope*(x-n))+l(n)
pt=[n,l(n)]
n=plot(16*x^2,(x,0,10))+ plot(m, (x,0,10),ymin=0 ) + point([1,16], color="red", size=40) + point([n,(l(n))], color="red", size=40) + text(slope,pt)
show(n)

n
#18
var("n")
@interact
def graph(n=(1.1,10)):
l=16*x^2
slope=(l(n)-16)/(n-1)
m=(slope*(x-n))+l(n)
pt=[n,l(n)]
pts=[1,16]
n=plot(16*x^2,(x,0,10))+ plot(m, (x,0,10),ymin=0 ) + point([1,16], color="red", size=40) + point([n,(l(n))], color="red", size=40) + text(slope,pt) +text(32,pts)
show(n)

n
#19
plots=[]
points=[-3,-2,-1,1,2,3]
equ=3*x^2
for q in points:
df=diff(3*x^2,x)
line=(df(q)*(x-q)+equ(q))
p=plot(3*x^2,(x,-5,5),ymin=-5,ymax=5)+plot(line,(x,-5,5),ymin=-5,ymax=20)
plots.append(p)
animate(plots)



plots=[]
points=[-3,-2,-1,0,1,2,3]
equ=3*x^2#its always a good idea to define the equation separately somewhere so you dont have to type it over and over
for q in points:
df=diff(3*x^2,x)
#you have to put q into the differential equation to get the slope for the line at that point
line=(df(q)*(x-q))+equ(q)#this is the equation for the line
p=plot(3*x^2,(x,-5,5), ymin=-5, ymax=20)+plot(line, (x,-5,5), ymin=-5, ymax=20)#replace df (which will always be the same) with line. Always specify both plots with the same boundaries so that the picture doesn't look wonky or shift
plots.append(p)
animate(plots)