% Compares ode45() and series solution for 
% x'' + t x = 0
% From class on 10-13-17

close all; clear all;
tfinish = 20;
x0 = 1; xd0 = 1;

[t,y] = ode45(@seriesex1rhs,[0 tfinish],[x0 xd0])
plot(t,y(:,1)); hold on;

a0 = x0;
a(1) = xd0; a(2) = 0;
x = a0*t.^0 + a(1)*t.^1 + a(2)*t.^2;
n=1;
a(n+2) = -1/((n+2)*(n+1))*a0;
x = x + a(n+2)*t.^(n+2);
for n=2:100
   a(n+2) = -1/((n+2)*(n+1))*a(n-1); 
   x = x + a(n+2)*t.^(n+2);
end

plot(t,x);
axis([0 tfinish -3 3])
