% OCW Universidad de Cantabria
% Cálculo Simbólico y Numérico en Ecuaciones Diferenciales
% © Cursos 2001-2014,  M. Eugenia Pérez, UC
%
function y= vibracionescuerda(n)
% 
% lee n  el número de términos de la aproximación  
syms x t
f=(heaviside(x-1/4)-heaviside(x-3/4))*((x-1/2)^2-1/16);
% 
u=0;
for i=1:n
    c(i)=double(int(sin(i*pi*x)*f,x,0,1)/int((sin(pi*i*x))^2,x,0,1)); %  
   u=u+c(i)*sin(pi*i*x)*cos(pi*3*i*t);%  
end
% 
aproximacion=vpa(u,4); %  
% 
 u_n=u;
solucion=vpa(u,4)
%  
ezsurf(u_n,[0,2],[0,1])
% 
pause
ezplot(subs(u_n,t,0),[0,1])
axis([0,1,-0.1,0.1])
pause
%  
ezplot(subs(u_n,t,0.1),[0,1])
axis([0,1,-0.1,0.1])
pause
%  
ezplot(subs(u_n,t,0.1),[0,1])
axis([0,1,-0.1,0.1])
pause
%  
ezplot(subs(u_n,t,0.3),[0,1])
axis([0,1,-0.1,0.1])
pause
%  
ezplot(subs(u_n,t,0.4),[0,1])
axis([0,1,-0.1,0.1])
% 
pause
ezplot(subs(u_n,t,1/2),[0,1])
axis([0,1,-0.1,0.1])
pause
% en t=1
ezplot(subs(u_n,t,1/2+0.1),[0,1])
axis([0,1,-0.1,0.1])
pause
%  
axis([0,1,-0.1,0.1])
pause
%  
ezplot(subs(u_n,t,1/2+0.1),[0,1])
axis([0,1,-0.1,0.1])
pause
% en t=1
ezplot(subs(u_n,t,1/2+0.3),[0,1])
axis([0,1,-0.1,0.1])
pause
%  
ezplot(subs(u_n,t,1/2+0.4),[0,1])
axis([0,1,-0.1,0.1])
pause
ezplot(subs(u_n,t,1),[0,1])
axis([0,1,-0.1,0.1])
pause
% 
ezplot(subs(u_n,t,3/2),[0,1])
axis([0,1,-0.1,0.1])
pause
%  
ezplot(subs(u_n,t,2),[0,1])
axis([0,1,-0.1,0.1])
pause
% 
ezplot(subs(u_n,t,2+1/2),[0,1])
axis([0,1,-0.1,0.1])
pause
% 
ezplot(subs(u_n,t,3),[0,1])
axis([0,1,-0.1,0.1])
pause
%  
 moviein(80); %  
for j=1:81
   dt=(j-1)*0.1
w=subs(u_n,t,dt);
ezplot(w,[-1,1]);
axis([0,1,-0.1,0.1])
    % pause
   M(:,j)=getframe;
end
      movie(M,1,3)%   

 

