CoCalc Shared FilesLab 5 / Lab5-turnin.sagewsOpen in CoCalc with one click!
Author: Kelly Truong
Views : 32
# Lab 5: # Name: Kelly Truong # I worked on this code with: Haylee # 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 # use enough comments that you and the grader can understand your code. #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()
#2Exercise 2. Compute the average rate of change of h(x) between x = 3.5 and x = 5.5. (h(5.5)-(3.5))/(5.5-3.5)
873.801672411853873.801672411853
#3 Exercise 3. Create a list of average rates of change for h(x) for ∆x values of #1, 0.1, 0.01, and 0.001. (You can do this by hand or use a loop.) Use the result #to estimate the function’s rate of change at x = 3.5. Why do you think the #number you gave is the rate of change at that value of x? ROC = [] for i in [1,0.1,0.01,0.001] : ROC.append((h(3.5+i)-h(3.5))/i) ROC #bc we're using the formula for instantaneous ROC h(t+∆t) - h(t) / ∆t i is the rate of change because it is the difference between h(3.5+i) and h(3.5)
[35.406127367267535.4061273672675, 180.370758684909-180.370758684909, 184.519899054203-184.519899054203, 184.827614891589-184.827614891589]
#4Exercise 4. Estimate the instantaneous rate of change at another point (as ou did in Exercise 3). ROC = [] for i in [1,0.1,0.01,0.001] : ROC.append((h(2.3+i)-h(2.3))/i) ROC
[130.063835124014-130.063835124014, 70.5949390572499-70.5949390572499, 65.2122897437451-65.2122897437451, 64.6887513129357-64.6887513129357]
##5 Find the average rates of change for the function f(t) = 1000t^2 at t = 1 using 1, 0.1, 0.01, and 0.001 as your values of ∆t. Then, estimate the function’s rate of change at t = 1. Feel free to use more ∆t values if you want. f(t)=1000*t^2 ROC =[] for i in [1,0.1,0.01,0.001] : ROC.append((f(1+i)-f(1))/i) ROC
[30003000, 2100.000000000002100.00000000000, 2010.000000000002010.00000000000, 2000.999999999752000.99999999975]
#6Exercise 6. Repeat this procedure for g(t) = 1, 000, 000t^2. What is this function’s rate of change at t = 1? g(t)=1000000*t^2 ROC =[] for i in [1,0.1,0.01,0.001] : ROC.append((g(1+i)-g(1))/i) ROC
[30000003000000, 2.10000000000000×1062.10000000000000 \times 10^{6}, 2.01000000000000×1062.01000000000000 \times 10^{6}, 2.00099999999965×1062.00099999999965 \times 10^{6}]
#7 Exercise 7. Drawing on your results, briefly explain why limits are necessary when computing derivatives. Why don’t we just pick a small value of ∆t and always use that? #because the formula uses the limit of ∆t as it approaches 0, and we can't use 0 because you can't divide by 0. We don't just use a single small point of delta t because it looks at what value the derivative goes as x approaches 0 not just a single point #8 ise 8. Compute x^3x^7 (x^3)*(x^7)
x10x^{10}
#9 Find the type of x. type(x)
<type 'sage.symbolic.expression.Expression'>
#10 Exercise 10. Factor x^2 + 7x + 6. factor(x^2+7*x+6)
(x+6)(x+1){\left(x + 6\right)} {\left(x + 1\right)}
#Exercise 11. Factor k^2 − 5k + 6. var("k") factor(k^2-5*k+6)
kk
(k2)(k3){\left(k - 2\right)} {\left(k - 3\right)}
# 12 Plot the function f(n) = 2n using n as the independent variable. You don’t need to define the function before plotting it. f(n)=2^n plot(f(n), (n,-10,10))
#13 Exercise 13. Why is the horizontal line y=8 rather than some other value of y? #because the symbolic variable x was assigned the number 2, so instead of plotting the theoretical graph of x^3, it performed math operations and resulted in 8 and plotted a straight line on 8 #144. Plot the function h(x) = 16x^2 for values of x between 0 and 5. Overlay the point (1,16) on the graph and make sure the point is visible. var("x") h(x)=16*x^2 plot(h(x), (x,0,5)) + point([1,16],color ="red", size = 40)
xx
#15 Create an animation that zooms in on this point by reducing the range of x. Use at least five different zoom levels. What do you observe? plots = [] zoom =srange(1,2,0.3) #values in the list have to be small for z in zoom : p=plot(h(x),(x,z-1,3-z)) + point([1,16],color ="red", size = 40) #changes happen to the x axis range, have to subtract from both sides so they approach towards the middle plots.append(p) a=animate(plots) show(a)
#16 Exercise 16. Create an interactive that plots the function f(x) = 16x^2 and a line that passes through the point (1,16) and a second point on the function whose x-coordinate is set by the slider. Describe what happens as the movable point approaches the fixed one. var("x") f(x)=16*x^2 @interact def coor(c=(5,0)) : m=(f(c)-f(1))/(c-1) p=plot(f(x),(x,-5,5)) + point([1,16],color ="purple", size = 50) + point([c,f(c)], color = "pink", size = 50) + plot(m*(x-1)+16, (x,-5,5),color="green") show(p)
xx
Interact: please open in CoCalc
#17 You can display a number on a plot using the text function. The syntax to display the value val at point pt on a plot is text(val, pt). (As in other cases, you can give the coordinates of pt as a list.) #Modify your interactive so it computes and displays the slope of the line being plotted. HINT: Use + to overlay text on a plot. var("x") f(x)=16*x^2 @interact def coor(c=(5,0)) : m=(f(c)-f(1))/(c-1) p=plot(f(x),(x,-5,5))+point([1,16],color ="purple", size = 50) + point([c,f(c)], color = "pink", size = 50) + plot(m*(x-1)+f(1), (x,-5,5),color="green") + text(m,(c,f(c)+30)) show(p)
xx
Interact: please open in CoCalc
#18 Exercise 18. Modify your interactive to also compute and display the derivative of the function at the point (1,16) (NOT the point moved by the slider). What do you notice about the derivative of the function and the slope of the plotted line?
var("x") f(x)=16*x^2 slp = diff(f(x),1) @interact def coor(c=(5,0)) : m=(f(c)-f(1))/(c-1) slp = diff(f(x),1) p=plot(f(x),(x,-5,5))+point([1,16],color ="purple", size = 50) + point([c,f(c)], color = "pink", size = 50) + plot(m*(x-1)+f(1), (x,-5,5),color="green") + text(slp.subs(x=1),(1,16+30)) + text(m,(c,f(c)+30)) #just needed the text above the anchor point so you can observe the slope of the secant show(p) #as the secant line gets closer to the anchor point/tangent the slope gets closer to the instantaneous rate of change of the anchor point
x
Interact: please open in CoCalc
#19 Exercise 19. Use diff to create an animation showing the tangent line to a function at different points, like the one at f(x)=16*x^2 plots = [] zoom =[-4,-2,0.1,2,4] for z in zoom : d =diff(f(x),x) p=plot(f(x),(x,-5,5), ymin = -100, ymax =400)+ plot((d.subs(x=z))*(x-z)+f(z), (x,-5,5), color ="green") plots.append(p) a=animate(plots) show(a)