% MATH 447 Project 3 Step 4: Step 2
function F = project3step42(s)
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);
findt = @(tnew) (adapquad(fnew,0,tnew,tol0)/length)-s;
t=0;
for i=1:20
    tnew=t-(findt(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);
    findt = @(t) (adapquad(fnew,0,t,tol0)/length)-s;
end
tnew

 T = 0:.01:1;
 plot(x(T),y(T));hold on
 xplot = x(tnew);
 yplot = y(tnew);
 plot(xplot,yplot,'k*')