I have the following program which generates the plot from a data list(i.e. Data1). However I want to print some plots for some values of the parameter "a". How would I proceed to print the scatter plots in the For loop (side by side as a table preferrably). The Code is as follows.
Data1 = {};
del = 0.1;
delx = 1/del;
n = 10;
a = 2;(* I would like to use various values of this variable in a loop throughout the code*)
(*************From Here************)
Vx = SparseArray[{}, {n, n}];
For[k = -2*Pi/a, k <= 2*Pi/a, k = k + 0.01,
ConsMat = ((k^2)/2)*IdentityMatrix[n];
dfdx = (SparseArray[{Band[{1, 2}] -> -I*k*delx,
Band[{2, 1}] -> I*k*delx, {1, n} ->
I*k*delx, {n, 1} -> -I*k*delx}, {n, n}]);
d2fdx2 = -1*
SparseArray[{Band[{1, 1}] -> -(delx^2), Band[{1, 2}] -> delx^2,
Band[{2, 1}] -> delx^2, {1, n} -> delx^2, {n, 1} -> delx^2}, {n,
n}];
p = 1;
For[x = 1, x <= 5, x = x + 5/n,
Vx[[p, p]] = (Cos[2 Pi*x/a] - 1);
p++;
];
p = 1;
Hamil = (dfdx + d2fdx2 + ConsMat) + Vx;
EigenVal = Eigenvalues[Hamil];
For[j = 1, j <= Length[EigenVal], j++,
Coord = {k, EigenVal[[j]]};
AppendTo[Data1, Coord];
];
];
ListPlot[Data1]
(**************To Here********************)
For
loops in Mathematica. You can usePrint
to display multiple plots in a loop, e.g.Do[Print@Plot[Sin[k x], {x, 0, 10}], {k, 1, 5}]
. Or you can useTable
to collect them into a list.Table[Plot[Sin[k x], {x, 0, 10}], {k, 1, 5}]
. UseColumn
orRow
to format the list. $\endgroup$