Question: Random points in a for cycle

I have use a ''for cycle'' in order to get a series of points. I would like to save those points in a vector in order to use it for the ''PolynomialFit'' comand. The problem is that the points that I save are sort randomly. How can I take the value of the vector A in the right sequence? in the underline string you can plot the walue of A over t (which is not sorted). I can not use the sort command as I used for t even for A because the points are not increasing.

This is my code:

restart;

Atot := 0:

for ii from 0 by 0.01 to 2 do

PtotFkt := ii->  ii^2 :

Ptot := PtotFkt(ii):

Atot := Atot+0.01*Ptot:

A[ii] := Atot: #Save points in a Table

t[ii] := ii: #Save point in a table

end do;

AV := convert(A, list): #conversion from table to list
nops(AV);  #number of points

timme := convert(t, list): #conversion from table to list
nops(timme); #number of points

 

with(Statistics); #PolynomialFit

X := Vector(AV, datatype = float);

Y := Vector(sort(timme), datatype = float);

plot(Y, X, style = point, symbol = asterisk, color = blue);

regress := PolynomialFit(10, X, Y, time);

curve1 := plot(regress, time = 0 .. 2);

Please Wait...