# Practice-Lkhagva

## 2209 days ago by bigdata2016

x=vector(QQ, [1, 2, -3, 4]) y=vector(QQ, [-2, 4, 1, 0]) z=vector(QQ, [5, -2, 3, -7]) t=vector(QQ, [2, 2, 3, 5]) print "2*x-3*y+z-t=", 2*x-3*y+z-t vectors = [x, y, z, t] scalars = [2, -3, 1, -1] multiples = [scalars[i]*vectors[i] for i in range(4)] print "a*x+b*y+c*z+d*t=", sum(multiples)
 2*x-3*y+z-t= (11, -12, -9, -4) a*x+b*y+c*z+d*t= (11, -12, -9, -4) 2*x-3*y+z-t= (11, -12, -9, -4) a*x+b*y+c*z+d*t= (11, -12, -9, -4)
x=vector([2, -1, 3, 2]) y=vector([3, 2, 1, -4]) print x.inner_product(y) print x.norm() print "cos(theta)= ", x.inner_product(y)/(x.norm()*y.norm())
 -1 3*sqrt(2) cos(theta)= -1/180*sqrt(2)*sqrt(30) -1 3*sqrt(2) cos(theta)= -1/180*sqrt(2)*sqrt(30)
A=matrix(QQ,[[25, 15, -5], [15, 18, 0], [-5, 0, 11]]) L=A.cholesky() print L
 [ 5 0 0] [ 3 3 0] [-1 1 3] [ 5 0 0] [ 3 3 0] [-1 1 3]
print A.inverse() L*L.transpose()==A
 [ 22/225 -11/135 2/45] [-11/135 10/81 -1/27] [ 2/45 -1/27 1/9] True [ 22/225 -11/135 2/45] [-11/135 10/81 -1/27] [ 2/45 -1/27 1/9] True
b=vector([1, 2, 3]) A.solve_right(b)
 (46/675, 22/405, 41/135) (46/675, 22/405, 41/135)
f(x) = x^2 a = 0.0 b = 2.0 table = [] exact = integrate(f(x), x, a, b) for n in [4, 10, 20, 50, 100]: h = (b-a)/n midpoint = sum([f(a+(i+1/2)*h)*h for i in range(n)]) trapezoid = h/2*(f(a) + 2*sum([f(a+i*h) for i in range(1,n)])+ f(b)) simpson = h/3*(f(a) + sum([4*f(a+i*h) for i in range(1,n,2)])+ sum([2*f(a+i*h) for i in range (2,n,2)]) + f(b)) table.append([n, h.n(digits=2), (midpoint-exact).n(digits=6), (trapezoid-exact).n(digits=6), (simpson-exact).n(digits=6)]) html.table(table, header=["n", "h", "Midpoint rule", "Trapezoidal rule", "Simpsonâ€™s rule"])
 Traceback (click to the left of this block for traceback) ... IndentationError: expected an indented block Traceback (most recent call last): h = (b-a)/n File "", line 1, in File "/tmp/tmp2E47EY/___code___.py", line 9 h = (b-a)/n ^ IndentationError: expected an indented block
f(x) = x^2-5*x+10 f = Piecewise([[(0,10), f]]) g = f.riemann_sum(6, mode="midpoint") F = f.plot(color="blue") R = add([line([[a,0],[a,f(x=a)],[b,f(x=b)],[b,0]], color="red") for (a,b), f in g.list()]) show(F+R)
(4^25+5^16).factor (
 -1/(u + 1) + 1/u  -1/(u + 1) + 1/u 
var('x,y') plot3d((16-x^2)^(1/2), (y,0,4), (x,0,4))
 Sleeping...

(4^125+5^64).factor ()
 1547881 * 2291213 * 18564532093913667026708643550789 * 27479692856067389975525373924697 1547881 * 2291213 * 18564532093913667026708643550789 * 27479692856067389975525373924697
circle((1,1), 1) + plot(x^2, (x,0,5))