Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 5222
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 #delt=(b-a)/n L=[a+delt*j for j in range(n+1)] # L is a list of end points of subintervals #a+n*delt=b # 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(((a+b)/2)+k*delt for k in range(n)) else: S=sum(b-k*delt for k in range(n)) return S*delt
#My example: riemann_sum(x^3-3*x^2,0,2,30,0).n()
1.93333333333333
#Your example: riemann_sum(2*x^3-3*x^2+x,0,3,40,0).n()
4.38750000000000
#######################
#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-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,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*cos(x) integral_MVT(f,0,2*pi)
############################
# 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
f_plot=plot(x(t),-3,t,3) x_plot=plot(y(t),-3,t,3)
(f_plot+x_plot).show()
########################
#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 0x7f1483e590c8> (A, B, C)
a=1/sqrt(A);b=sqrt(A/A*C-B^2)
pi/sqrt(1/4-4/25)
10/3*pi
A=0.25;B=0;C=1 a=1/sqrt(A);b=sqrt(A/A*C-B^2) a
2.00000000000000
b
1.00000000000000
x(t)=2*cos(t)-(8/3)*sin(t) y(t)=(5/3)*sin(t) p=parametric_plot(((x(t),y(t)),(t,0,2*pi)),figsize=[4,3],thickness=2);p
Error in lines 3-3 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1191, in execute flags=compile_flags), namespace, locals) File "", line 1, in <module> File "/ext/sage/sage-8.9_1804/local/lib/python2.7/site-packages/sage/misc/decorators.py", line 493, in wrapper return func(*args, **options) File "/ext/sage/sage-8.9_1804/local/lib/python2.7/site-packages/sage/plot/plot.py", line 2625, in parametric_plot raise ValueError("the number of functions and the number of variable ranges is not a supported combination for a 2d or 3d parametric plots") ValueError: the number of functions and the number of variable ranges is not a supported combination for a 2d or 3d parametric plots
︠d00e226f-d027-4acb-a62d-154d302b97fa︠ ################################################################################# ︠406aed5f-f1dc-4210-9a9b-0a9bae8c3543︠ # 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 #######################