Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 534
reset
<function reset at 0x7f591d340ed8>
#################### # Exercise 1 #Exercise 1. Make a CAS function riemann_sum(f, a, b, n, c) that takes five inputs: #•end points a,b, a<b,of interval of integration #•function f continuous on the interval #•positive integer n, the number of subintervals of equal length in partition of interval [a,b] #•and parameter p. #The function returns #• left Riemann sum if c = 0; #• middle Riemann sum if c = 1; #• right Riemann sum if c = 2 #Test your function on example of your choice. def riemann_sum(f,a,b,n,p):#p takes only one of the values 0, 1, 2 #Define the partition of the interval [a,b] into n subintervals of equal length: delt=(b-a)/n #encode the length of a subinterval L=[a+delt for j in range(n+1)] # L is a list of end points of subintervals # For each case below S is the sum of the given function values at appropriate x-values if p==0: S=sum(a+k*delt for k in range(n)) elif p==1: S=sum(f(a+(2*k-1)*delt/2) for k in range(1,n+1)) else: S=sum(f(a+k*delt) for k in range(1,n+1)) return S*delt
#My example: riemann_sum(x^3-3*x^2,0,2,30,0).n()
1.93333333333333
#Your example:
riemann_sum(x^4-4*x^3,0,3,30,0).n()
4.35000000000000
#######################
#Exercise 2 #Make a CAS function integral_MVT(f, a, b) that takes the end points of a closed interval and a continuous function defined on this interval and returns a figure with the graph of the function and the line y=f__ave. Here f_ave is the average value of the function f on the interval [a,b]. def integral_MVT(f,a,b): G=Graphics() #Make a plot of f on [a,b]: fcn_plot=plot(f,a,b,legend_label="f(x)",figsize=[4,2],thickness=2) G+=fcn_plot #Find the average value of f on [a,b]: f_ave=f.integral(x,a,b)/(b-a) #Find location of the point c s.t. f(c)=f_ave c=find_root(f(x)-f_ave,a,b) #Define the constant function equal the f_ave on [a,b] and make a plot of the function f_c(x)=f(c) f_ave_plot=plot(f_ave,a,b,thickness=2,legend_label="line y=f_ave",linestyle="dashed") G+=f_ave_plot # Make a plot of two points, c on the x-axis and corresponding point on the graph of f pt_plot=point([[c,0],[c,f(c)]],size=40,color='red') G+=pt_plot return G.show() #My example: f(x)=3*sin(x) integral_MVT(f,0,pi)# Include your own example
# Your example:
f(x)=2*e^(x) integral_MVT(f,0,8)
############################
# Exercise 3 #Consider the parametric curve x=t^2-4, y=t-t^3, -2<=t<=2. #Plot the curve. You will see two parts of the area bounded by the curve, a curvilinear triangle and a loop. #Consider only the area bounded by the curvilinear triangle. Use CAS assistance to find the vertical line that halves the area bounded by this curve. Make a figure with the curve plot and the vertical line. Show your work.
var("t") x(t)=(t^2)-4 y(t)=t-(t^3)
t
x(t)=t^2-4; y(t)=t-t^3
x(t)=t^2-4; y(t)=t-t^3
curve=parametric_plot((x(t),y(t)),(t,-2,2));curve part1=parametric_plot((x(t),y(t)),(t,-2, -1));part1
A=integral(y(t)*2*t,(t,-1,2));A
-36/5
S(p)=integral(y(t)*2*t,(t,-1,p))
########################
#Mini project: Area of the tilted ellipse #Part 1. Find the general formula for the area of ellipse that is defined by the formula #A*x^2+2*B*x*y+C*y^2 = 1 with B^2-A*C < 0. #Hint: Apply the completing the square technique to the first two terms in the lhs of the given equation. This allows you to rewrite the given equation in the form ((x+k)^(2))/(a^(2))+(y^(2))/(b^(2))=1 with k, a, b depending on parameters A, B, C. Then think about relation between the area of standard ellipse and the area of its image under shear transformations #Part 2. Apply the formula derived in Part 1 to the ellipse with parameters A = 1/4, B = 2/5, C = 1. #Plot the given (sheared) ellipse and the corresponding standard ellipse in one figure.
reset var('A B C')
<function reset at 0x7fdf794520c8> (A, B, C)
#part 1 a=1/sqrt(A); b=sqrt(A/(A*C-B^2)) #part 2 pi/sqrt(1/4-4/25)
10/3*pi
A=0.25;B=0.4;C=1 a=1/sqrt(A); b=sqrt(A/(A*C-B^2)) a
2.00000000000000
b
1.66666666666667
x=2*cos(t) y=5/3*sin(t)
x(t)=2*cos(t)-8/3*sin(t) y(t)=5/3*sin(t) parametric_plot((x(t),y(t)),(t,0,2*pi))
# Mini project: Lorenz curve and the Gini index # Fill in the gaps following the steps suggestes in Lecture 7 or do the project your own way. #Step 1 #(a) #(b) #(c) #Step 2 #Step 3 #######################