tic;
thetas = linspace(0,pi/2)';
impacts = 0*thetas;
for j = 2:length(thetas)
  impacts(j) = ftarget(thetas(j),opt);
end
t1 = toc;

tic;
[D,x] = cheb(10);
thetac = (x+1)*pi/4;
impactsc = 0*thetac;
for k = 1:length(thetac)-1
  impactsc(k) = ftarget(thetac(k), opt);
end
t2 = toc;

tic;
impactsh = chebeval(impactsc, 4/pi*thetas-1);
t3 = toc;

plot(thetas, impacts);
fprintf('Time to evaluate at 100 points (ode45): %e\n', t1);
fprintf('Time to evaluate at 100 points (proxy): %e\n', t3);
fprintf('Time to fit poly: %e\n', t3);
fprintf('Max error: %e\n', norm(impacts-impactsh, inf));

