Question: How plot output of algorithm, where number of steps are unknown before running the algorithm?

Hello everybody, I tried to plot the output of my algorithm as follows below, defining two vectors representing the output values of each algortihm iteration. However, in this little example this is easy, because I know the number of steps, i.e. 3. However, how can I work out this problem, if I don't know the number of steps in advance? That is, how can I define a vector which grows in size with the number of algoithm steps, but which keeps the old values of the previous steps as well? > restart: with(stats): Digits := 14: > > N := 4: > L := 0.002: > beta:=0.85: > beta:=0.85: > cost := Vector([2000,100,700,1000]): > lambda := Vector([0.2,0.6,0.3,0.7]): > Lambda := add(lambda[i], i=1..N): > DFR := s -> ( add(lambda[i]*add((L*lambda[i])^k*exp(-L*lambda[i])/k! > , k = 0 .. s[i]-1) > , i = 1 .. N) > / Lambda ): > > IN := Matrix(N,N,shape=identity): > S := Vector[row](N): > maxDFR := DFR(S): z:=1; SFR:=Vector[row](3); Inv:=Vector[row](3); > while maxDFR <> prevDFR := maxDFR; > maxdelta := 0; > for k to N do > Sk := S + IN[k,1..N]; > DFRk := DFR(Sk); > delta := (DFRk - prevDFR)/cost[k]; > if delta > maxdelta then > maxdelta := delta; > maxDFR := DFRk; > Snxt := Sk; > end if; > end do; > S := Snxt; SFR[z]:=maxDFR; Inv[z]:=S.cost; printf("B = %g\n", S); printf("SFR = %.14g\n", SFR[z]); printf("I = %g\n\n", Inv[z]); z:=z+1 > end do; pair := (Inv,SFR) -> [Inv, SFR]; P:= zip( pair, Inv, SFR); plot(P);
Please Wait...