Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 5222
reset
<function reset at 0x7f65d8ebf0c8>
####################pbset 7 # 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,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)=x^2+2 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,figsize=[4,3]) x_plot=plot(y(t),-3,t,3,figsize=[4,3])
(f_plot+x_plot).show()
part1=parametric_plot((x(t),y(t)),(t,-2,1));part1
#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 0x7f7926cb30c8> (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.4;C=1 a=1/sqrt(A);b=sqrt(A/A*C-B^2) a
2.00000000000000
b
0.916515138991168
x(t)=(2*cos(t)) y(t)=((5/3)*sin(t)) p=parametric_plot((x(t),y(t)),(t,0,2*pi),figsize=[4,3],thickness=2);p
x(t)=(2*cos(t)-(8/3)*sin(t)) y(t)=((5/3)*sin(t)) q=parametric_plot((x(t),y(t)),(t,0,2*pi),color='red',figsize=[4,3],thickness=2);q+p
## E1 incorrect, -3; E2: 2/2.Extra points: +2. Total: 4/5
reset
<function reset at 0x7f239476d0c8>
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
##################################################### #Mini project: Projectile motion reset
<function reset at 0x7f65d8ebf0c8>
### Your solution for Step 1 goes here x0=0; y0=2; l=20; h=3.5; V=15;H=2;g=9.81 var('alpha') # Governing equations: m*x'=0, m*y'=-m*g. # Initial conditions:x0=0,y0=H,vx=V*cos(alpha),vy=V*sin(alpha) # Solution: x(t)=V*cos(alpha)*t y(t)=-g*(t^2/2)+V*sin(alpha)*t+H
alpha
# You code goes here # Write the equation x(tfence)=(fence location) using solution x(t) found on Step 1 #Solve the equaiton for tfence tfence=l/(V*cos(alpha));tfence # tfence involves the unknown parameter $\alpha$.
4/3/cos(alpha)
# Write the equation y(tfence)=h using th solution for y(t) found on Step 1. eq=y(tfence)==h;eq
20*sin(alpha)/cos(alpha) - 8.72000000000000/cos(alpha)^2 + 2 == 3.50000000000000
#Use the identity 1/cos(s)^2=1+tan(s)^2 to rewrite the equation as quadratic with respect to $z=tan(alpha)$ and solve for $z$. Use the dictionary type for your solution. var('z') eq_z=20*z-8.72*(1+z^2)-1.5==0 tan_alpha=solve(eq_z,z,solution_dict=True);tan_alpha
z [{z: -1/218*sqrt(6801) + 125/109}, {z: 1/218*sqrt(6801) + 125/109}]
# Now use the inverse of the function and find alpha1 and alpha2 from equation tan(alpha)=z alpha1=(arctan(tan_alpha[0][z])).n() alpha2=(arctan(tan_alpha[1][z])).n()
#Define parametric equations of the two trajectories #First trajectory: y1(t)=y(t).subs(alpha=alpha1);x1(t)=x(t).subs(alpha=alpha1) #Second trajectory y2(t)=y(t).subs(alpha=alpha2);x2(t)=x(t).subs(alpha=alpha2) #For each trajectory find the time when projectile hits the ground. Experiment with time range to bracket the solution or just play with plots to find the needed range tfinal1=find_root(y1(t),0,4) tfinal2=find_root(y2(t),0,4)
plot1=parametric_plot((x1(t),y1(t)),(t,0,tfinal1),color='green') plot2=parametric_plot((x2(t),y2(t)),(t,0,tfinal2),color='blue') (plot1+plot2).show()