 CoCalc Public FilesLab 5 / newLab5-turnin-1.sagews
Author: Derek Rivas
Views : 83
# Lab 5:

# Name: Derek Rivas
# 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
x1=3.5
x2=5.5
f_avg(x)=(h(x2)-h(x1))/((x2-x1))
f_avg

$x \ {\mapsto}\ 2.38517850947403 \times 10^{7}$
#3
x1=3.5
deltax=[0.1, 0.01, 0.001]
finst=[]

for i in deltax:
val=(h(x1+i)-h(x1))/i
finst.append(val)
finst

[$330873.802234064$, $285624.516938263$, $281557.678575831$]
#4
x3=1.2
deltax=[0.1, 0.01, 0.001, 0.0001]
finst=[]

for i in deltax:
val=(h(x3+i)-h(x3))/i
finst.append(val)
finst #values approach 136 as it gets closer to zero

[$164.024537585464$, $138.686997792651$, $136.432307573045$, $136.209400933254$]
#5
f(t)=1000*t^2
t1=1
deltat=[1, 0.1, 0.01, 0.001]
finst=[]

for i in deltat:
val=(f(t1+i)-f(t1))/i
finst.append(val)
finst

[$3000$, $2100.00000000000$, $2010.00000000000$, $2000.99999999975$]
#6
g(t)=1000000*t^2
t1=1
deltat=[0.1,0.01,0.001]
finst=[]

for i in deltatime:
val=((f(t1+i)-f(t1))/i)
finst.append(val)
finst

[$2100.00000000000$, $2010.00000000000$, $2000.99999999975$]
#7
#the limit allows for us to find a way to find only one order pair, if we use a small deltax it would still be only using another point
#the smallest deltax is still not zero

#8
x^3*x^7

$x^{10}$
#9
type("x")

<type 'str'>
#10
factor(x^2+7*x+6)

${\left(x + 6\right)} {\left(x + 1\right)}$
#11
var("k")

$k$
factor(k^2-5*k+6)

${\left(k - 2\right)} {\left(k - 3\right)}$
#12
var("n")

$n$
f(n)=2^n
plot(f(n), n,0,4, axes_labels=["n", "f(n)"]) #13
#the line is y=8 instead of another value of y because the points were plotted to have y as 8 and x at 0 along with the slope being zero

#14
h(x)=16*x^2
plot(h(x), (x, 0,5))+point([1,16], size=30) #15
plots=[]
x_zooms=[5,4,3,2,1]
for i in x_zooms:
p=plot(16*x^2, (x, 0, i) ) + point ([1,16])
plots.append(p)

animate(plots)

#16
@interact
def fprime(xcord=(0,20,1)):
f(x)=16*x^2
m=(f(xcord)-16)/((xcord)-1)
p=plot(f, (x, -10, 10))+plot(point([1,16]))+plot(m*(x-1)+16,ymin=-300, ymax=300)
show(p)

#17
@interact
def fprime(xcord=(0,20,1)):
f(x)=16*x^2
m=(f(xcord)-16)/((xcord)-1)
p=plot(f, (x, -10, 10))+plot(point([1,16]))+plot(m*(x-1)+16,ymin=-300, ymax=300)+text(m,[xcord,f(xcord)])
df=diff(f,x)
show(p)

#18
@interact
def fprime(xcord=(0,20,1)):
f(x)=16*x^2
m=(f(xcord)-16)/((xcord)-1)
p=plot(f, (x, -10, 10))+plot(point([1,16]))+plot(m*(x-1)+16,ymin=-300, ymax=300)+text(m,[xcord,f(xcord)])
df=diff(f,x)
show(p)
show(df(1))

#19
slopes=[]
trash=[-2,-1,0.1,2]
for t in trash:
df=diff(16*x^2,x)
s=df.subs(x=t)
p=plot(16*x^2, (x, -5,5), ymin=0, ymax=80, color="green")+plot(s*(x-t)+(16*t^2))
slopes.append(p)
a=animate(slopes)
show(a,gif=true) 