clear all; %y(t+2) + 0.25y(t) = 5, t>=0 %y(0) = 5, y(1) = 4,5 t=[1:30]; y(1) = 5; y(2) = 4.5; for m=3:30; y(m)=-0.25*y(m-2)+5; end stem(t,y,'o') stem(t,y) pause; plot(t,y,'*') pause plot(t,y) pause; f = @(new_y) interp1(t,y, new_y, 'spline'); x=[1:.1:30]; for i = 1:291 ff(i)=f(x(i)); end for i = 1:291 yte(i)=(0.5)^(x(i)-1)*(cos(pi/0.5*(x(i)-1))+sin(pi/0.5*(x(i)-1))) + 4; end plot(x,ff,'r-',x,yte, 'b:') xlabel ('tempo') ylabel ('y') title ('Curvas contínuas: spline (vermelha) e teórica (azul tracejado)') pause; clear yte; x2=[1:.4:30]; for i = 1:73 yte(i)=(0.5)^(x(i)-1)*(cos(pi/0.5*(x(i)-1))+sin(pi/0.5*(x(i)-1))) + 4; end plot(x,ff,'r-',x2,yte, 'b:') xlabel ('tempo') ylabel ('y') title ('Curvas contínuas: spline (vermelha) e teórica (azul tracejado)')