# Use "Plot" command inside "For" loop and superpose in same figure?

GROUPS:
 I wish to include a "Plot" command within a "For" loop. The loop numerically solves a differential equation in intervals (0,\tau), (\tau,2\tau) and so on, with the initial condition changing each time (the solution at \tau at the end of first iteration becomes initial condition for the second). In the attached file, the definitions of functions are all fine, but the main trouble comes while running the For loop: it produces the correct plots but in different figures. Can I superpose all these plots in the same figure, so as to get a single curve in the full range? Thanks in advance. Attachments:
4 days ago
4 Replies
 Gianluca Gorni 1 Vote This is one way: Anstot1 = NDSolveValue[{0.5 Derivative[1][\[Sigma]x][t] + ( k[t] \[Sigma]x[t])/\[Gamma] == ftot[t], \[Sigma]x[0] == ini}, \[Sigma]x, {t, 0, \[Tau]}]; Plot[Anstot1[Mod[t, \[Tau]]], {t, 0, 5 \[Tau]}] 
 Ok, you can give a name to each plot and combine them with Show: For[j = 0, j < 5, j++, Anstot1 = NDSolve[{0.5 Derivative[1][\[Sigma]x][t] + ( k[t] \[Sigma]x[t])/\[Gamma] == ftot[t], \[Sigma]x[0] == ini}, \[Sigma]x, {t, 0, \[Tau]}]; ini = \[Sigma]x[\[Tau]] /. Anstot1; pl[j] = Plot[\[Sigma]x[Mod[t, \[Tau]]] /. Anstot1, {t, j \[Tau], (j + 1) \[Tau]}] ]; Show[Table[pl[j], {j, 0, 4}], PlotRange -> All]