%MATH 447 Project 3 Step 3 n=5
x = @(t) .5+.3*t+3.9*t.^2-4.7*t.^3;
y = @(t) 1.5+.3*t+.9*t.^2-2.7*t.^3;
xprime = @(t) .3+7.8*t-14.1*t.^2;
yprime = @(t) .3+1.8*t-8.1*t.^2;
fnew = @(t) sqrt(xprime(t).^2+yprime(t).^2);
tol0 = 10^-4;
n = 5;
findt1 = @(t1new) (adapquad(fnew,0,t1new,tol0)/(adapquad(fnew,0,1,tol0)))-(1/n);
t1 = bisect(findt1,0,1,tol0);
findt2 = @(t2new) (adapquad(fnew,t1,t2new,tol0)/(adapquad(fnew,t1,1,tol0)))-(1/(n-1));
t2 = bisect(findt2,t1,1,tol0);
findt3 = @(t3new) (adapquad(fnew,t2,t3new,tol0)/(adapquad(fnew,t2,1,tol0)))-(1/(n-2));
t3 = bisect(findt3,t2,1,tol0);
findt4 = @(t4new) (adapquad(fnew,t3,t4new,tol0)/(adapquad(fnew,t3,1,tol0)))-(1/(n-3));
t4 = bisect(findt4,t3,1,tol0);

T = 0:.01:1;
plot(x(T),y(T));hold on
xplot = [x(0),x(t1),x(t2),x(t3),x(t4),x(1)];
yplot = [y(0),y(t1),y(t2),y(t3),y(t4),y(1)];
plot(xplot,yplot,'k*');axis([0 1.4 0 1.7]);title('Step 3 Figure; n=5');xlabel('x');ylabel('y')