%MATH 447 Project 3 Step 4: Step 3 
function F = project3step43(k)
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;
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) .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);
    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*')