Shared2017-10-27-181023.sagewsOpen in CoCalc
var('t')
h1(t)=(11/3)*t^2;
h2(t)=-(5/6)*2^t+3;
f(t)=piecewise([[(-pi,0),h1(t)],[(0,pi),h2(t)]])
uta=plot(f(t),t,-pi,pi)
uta

t
w1(t)=sin(t);
w2(t)=sin(2*t);
w3(t)=sin(3*t);

nor=integral((w1(t))^2,t,-pi,pi)
nor
pi
#si se sacan las otras normas  se observara que son iguales#
k1=integral(w1(t)*h1(t),t,-pi,0)+integral(w1(t)*h2(t),t,0,pi);
k2=integral(w2(t)*h1(t),t,-pi,0)+integral(w2(t)*h2(t),t,0,pi);
k3=integral(w3(t)*h1(t),t,-pi,0)+integral(w3(t)*h2(t),t,0,pi);

theta1(t)=(k1/nor)*w1(t);
theta2(t)=(k2/nor)*w2(t);
theta3(t)=(k3/nor)*w3(t);

pt(t)=theta1(t)+theta2(t)+theta3(t)
uu=plot(pt(t),(t,-pi,pi),color='black')
uv=plot(f(t),(t,-pi,pi),color='red')
uw=uu+uv
uw.show()

w5(t)=1
w6(t)=cos(t)
w7(t)=cos(3*t)
w8(t)=cos(5*t)
nor0=integral(w5(t)^2,t,-pi,pi)
nor0
2*pi
nor1=integral(w6(t)^2,t,-pi,pi)
nor1
pi
#la norma de w6,w7 y w8 es la misma la diferente es la primera norma
#aproximacion conjunto#1
#si se sacan las otras normas  se observara que son iguales#
k1=integral(w1(t)*h1(t),t,-pi,0)+integral(w1(t)*h2(t),t,0,pi);
k2=integral(w2(t)*h1(t),t,-pi,0)+integral(w2(t)*h2(t),t,0,pi);
k3=integral(w3(t)*h1(t),t,-pi,0)+integral(w3(t)*h2(t),t,0,pi);

theta1(t)=(k1/nor)*w1(t);
theta2(t)=(k2/nor)*w2(t);
theta3(t)=(k3/nor)*w3(t);
pt(t)=theta1(t)+theta2(t)+theta3(t)
u=plot(pt(t),(t,-pi,pi),color='black')

#aproximacion conjunto #2
#hacemos las proyecciones del vector sobre las funciones dadas
#hacemos el producto punto de cada funcion 
q0(t)=integral(w5(t)*h1(t),t,-pi,0)+integral(w5(t)*h2(t),t,0,pi)
q1(t)=integral(w6(t)*h1(t),t,-pi,0)+integral(w6(t)*h2(t),t,0,pi)
q2(t)=integral(w7(t)*h1(t),t,-pi,0)+integral(w7(t)*h2(t),t,0,pi)
q3(t)=integral(w8(t)*h1(t),t,-pi,0)+integral(w8(t)*h2(t),t,0,pi)
#con el producto punto se hacen las respectivas proyecciones
e0(t)=q0(t)*w5(t)/nor0
e1(t)=q1(t)*w6(t)/nor1
e2(t)=q2(t)*w7(t)/nor1
e3(t)=q3(t)*w8(t)/nor1
#sumamos las proyecciones para aproximar
et(t)=e0(t)+e1(t)+e2(t)+e3(t)
uu=plot(et(t),(t,-pi,pi),color='green')
uv=plot(f(t),(t,-pi,pi),color='blue')
uw=uu+uv
uw.show()
r0(t)=1
r1(t)=sin(t)
r2(t)=sin(2*t)
r3(t)=sin(3*t)
r4(t)=cos(t)
r5(t)=cos(3*t)
r6(t)=cos(5*t)
#al hacer la norma todas son iguales acxepto r0
nor0=integral(r0(t)^2,t,-pi,pi)
nor0
2*pi
nor1=integral(r1(t)^2,t,-pi,pi)
nor1
pi
#hacemos las proyecciones del vector sobre las funciones dadas
#hacemos el producto punto de cada funcion 
z0(t)=integral(r0(t)*h1(t),t,-pi,0)+integral(r0(t)*h2(t),t,0,pi)
z1(t)=integral(r1(t)*h1(t),t,-pi,0)+integral(r1(t)*h2(t),t,0,pi)
z2(t)=integral(r2(t)*h1(t),t,-pi,0)+integral(r2(t)*h2(t),t,0,pi)
z3(t)=integral(r3(t)*h1(t),t,-pi,0)+integral(r3(t)*h2(t),t,0,pi)
z4(t)=integral(r4(t)*h1(t),t,-pi,0)+integral(r4(t)*h2(t),t,0,pi)
z5(t)=integral(r5(t)*h1(t),t,-pi,0)+integral(r5(t)*h2(t),t,0,pi)
z6(t)=integral(r6(t)*h1(t),t,-pi,0)+integral(r6(t)*h2(t),t,0,pi)
#cada proyección
b0(t)=z0(t)*r0(t)/nor0
b1(t)=z1(t)*r1(t)/nor1
b2(t)=z2(t)*r2(t)/nor1
b3(t)=z3(t)*r3(t)/nor1
b4(t)=z4(t)*r4(t)/nor1
b5(t)=z5(t)*r5(t)/nor1
b6(t)=z6(t)*r6(t)/nor1
#la suma de las proyecciones para aproximar
bt(t)=b0(t)+b1(t)+b2(t)+b3(t)+b4(t)+b5(t)+b6(t)
uu=plot(bt(t),(t,-pi,pi),color='red')
uv=plot(f(t),(t,-pi,pi),color='blue')
uw=uu+uv
uw.show()