CoCalc Public FilesCalculsD1.sagews
Author: Juan Carlos Bustamante
Views : 51
Compute Environment: Ubuntu 18.04 (Deprecated)
typeset_mode(True)


### Question 2

A =matrix(QQ,[[2,1,-2,-1],[4,4,-3,1],[2,7,1,8]])
A.echelonize()
A

$\displaystyle \left(\begin{array}{rrrr} 1 & 0 & -\frac{5}{4} & -\frac{5}{4} \\ 0 & 1 & \frac{1}{2} & \frac{3}{2} \\ 0 & 0 & 0 & 0 \end{array}\right)$
B=matrix(QQ,[[5/4,5/4,-5],[-1/2,-3/2,10],[1,0,4],[0,1,-8]])
B.echelonize()
B

$\displaystyle \left(\begin{array}{rrr} 1 & 0 & 4 \\ 0 & 1 & -8 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{array}\right)$

### Question 4

u1=vector([3,0,4])
u2=vector([-1,0,7])
u3=vector([2,9,11])

def proj(p,q):#la projection de p sur q
return p.dot_product(q)/q.dot_product(q) * q

v1=u1
v2 = u2-proj(u2,v1)
v2

$\displaystyle \left(-4,\,0,\,3\right)$
v3 = u3-proj(u3,v1)-proj(u3,v2)
v3

$\displaystyle \left(0,\,9,\,0\right)$
v2.dot_product(v3)

$\displaystyle 0$

### Question 5

f1(x) = 1
f2(x)=cos(x)
f3(x)=sin(x)
h(x)=x^2

g1(x) = f1(x)/sqrt(integral(f1(x)*f1(x),x,-pi,pi))
g1(x)

$\displaystyle \frac{\sqrt{2}}{2 \, \sqrt{\pi}}$
g2(x) = f2(x)/sqrt(integral(f2(x)*f2(x),x,-pi,pi))
g2(x)

$\displaystyle \frac{\cos\left(x\right)}{\sqrt{\pi}}$
g3(x) = f3(x)/sqrt(integral(f3(x)*f3(x),x,-pi,pi))
g3(x)

$\displaystyle \frac{\sin\left(x\right)}{\sqrt{\pi}}$




c1 = integral(g1(x)*h(x),x,-pi,pi)
c1
c2 = integral(g2(x)*h(x),x,-pi,pi)
c2
c3 = integral(g3(x)*h(x),x,-pi,pi)
c3

$\displaystyle \frac{1}{3} \, \sqrt{2} \pi^{\frac{5}{2}}$
$\displaystyle -4 \, \sqrt{\pi}$
$\displaystyle 0$
H(x) = c1 * g1(x) + c2*g2(x)
CourbeH = plot(H(x),x,-pi,pi)
Courbeh = plot(h(x),x,-pi,pi, color="red")

C1 = plot(f1(x),x,-pi,pi, color="darkgreen", linestyle="dotted")
C2 = plot(f2(x),x,-pi,pi, color="darkgreen", linestyle="dotted")
C3 = plot(f3(x),x,-pi,pi, color="darkgreen", linestyle="dotted")
show(CourbeH + Courbeh + C1+C2+C3, figsize = 4)


La courbe bleue représente la projection de $h(x)$ sur l'espace engendré par les trois fonctions données dans l'énoncé. Il s'agit de la courbe qui peut approcher le mieux la parabole rouge, parmi toutes les courbes que l'on peut construire en faisant des combinaisons linéaires des trois fonctions données (en pointillés verts)




### Question 6

def ps(p,q):
return integrate(exp(-x^2)* p(x)*q(x),x,-infinity,infinity)

def pproj(p,q):
return ps(p,q)/ps(q,q)*q

u0(x) = 1
u1(x) = x
u2(x) = x^2

f0(x) = u0(x)
f0(x)

$\displaystyle 1$
ps(f0,f0)

$\displaystyle \sqrt{\pi}$
f1(x) = u1- pproj(u1,f0)
f1(x)

$\displaystyle x$
ps(f1,f1)

$\displaystyle \frac{1}{2} \, \sqrt{\pi}$
f2(x) = u2 - pproj(u2,f0) - pproj(u2,f1)
f2(x)

$\displaystyle x^{2} - \frac{1}{2}$
ps(f2,f2)

$\displaystyle \frac{1}{2} \, \sqrt{\pi}$
︠cd9f0bef-cbb3-4a5e-b61e-12b4ef292ac6︠