%MATH 447 Project 3 Step 4: Step 3 
function F = project3step6(k)

%Points used were (x1,y1)=(1,1),(x2,y2)=(1,3),(x3,y3)=(3,3),(x4,y4)=(2,2)
x = @(t) 1+6*t.^2-5*t.^3;
y = @(t) 1+6*t-6*t.^2+t.^3;
xprime = @(t) 12*t-15*t.^2;
yprime = @(t) 6-12*t+3*t.^2;
fnew = @(t) sqrt(xprime(t).^2+yprime(t).^2);
tol0 = 10^-4;
length = (adapquad(fnew,0,1,tol0));

for n=1:k-1
findt1 = @(t) (adapquad(fnew,0,t,tol0)/length)-(n/k);
t=0;
for i=1:20
    tnew=t-(findt1(t))/(fnew(t)/length);
    t=tnew;
    xprime = @(t) 12*t-15*t.^2;
    yprime = @(t) 6-12*t+3*t.^2;
    fnew = @(t) sqrt(xprime(t).^2+yprime(t).^2);
    findt1 = @(t) (adapquad(fnew,0,t,tol0)/length)-(n/k);
end
tstar(n)=tnew;
end

 T = 0:.01:1;
 plot(x(T),y(T));hold on
 xplot = x(tstar);
 yplot = y(tstar);
 plot(xplot,yplot,'k*');title('Step 6 Figure; n = 15');xlabel('x');ylabel('y')