# Using a loop to build a list

I'm trying to take a list and then plot it with complex variables.

However, when I'm making my list I keep getting

Recursion depth of 1024 exceeded during evaluation of {test, nu}

and my list is not getting written to. It's probably a simple to fix, but

Here is what I have:

sig= -15
While[sig <12, tau = Sqrt[sig + 4];
nu = Tan[sig - (1/sig)*E^(sig)];
Print[sig, nu];
sig = sig + 1.00];
For[sig, test= {test, nu}];
ListPlot[test, sig]


This is probably just poorly written code, but I'm not quite sure what I'm doing wrong. Any help would be appreciated!

• Before you get to the plot part, you need to fix your While loop. What happenes when sig=0 and you have 1/sig in there? Did you not hear a beep when you run the While loop? may be the sound was off on your computer, but my PC beeped loud and then noticed you are dividing by zero. You are starting from -15 and end at 12 so it will pass through 0 Nov 8, 2017 at 1:09
• Oh yeah, you're right. If I try to fix that, then it says that there are too many arguments in the loop. I could just replace the value of sig to -15.01.
– Kir
Nov 8, 2017 at 1:26
• Is this what you really want: Plot[Tan[sig - (1/sig)*E^(sig)], {sig, -15, 12}] Nov 8, 2017 at 1:42
• I don't really want to use Plot because I'm just searching for test points to use and then to use ListPlot in order to show each individual thing, not its own connection.
– Kir
Nov 8, 2017 at 1:46
• Your For is of incorrect syntax. It needs at least 3 parameters; ideally 4. You only have 2 parameters. Your ListPlot is also of incorrect syntax. Check the documentation. Nov 8, 2017 at 2:26

data =
Module[{sig = -15., tau, nu, pts = {}},
While[sig < 12.,
tau = Sqrt[sig + 4];
nu = Quiet @ Check[Tan[sig - (1/sig)*E^(sig)], Null];
pts = Join[pts, {{sig, tau, nu}}];
sig++];
pts]

{{-15., 0. + 3.31662 I, 0.855993}, {-14., 0. + 3.16228 I, -7.2446},
{-13., 0. + 3. I, -0.463021}, {-12., 0. + 2.82843 I, 0.635861},
{-11., 0. + 2.64575 I, 226.028}, {-10., 0. + 2.44949 I, -0.648354},
{-9., 0. + 2.23607 I, 0.452332}, {-8., 0. + 2. I, 6.80169},
{-7., 0. + 1.73205 I, -0.871219}, {-6., 0. + 1.41421 I, 0.291454},
{-5., 0. + 1. I, 3.39734}, {-4., 0., -1.14716},
{-3., 1., 0.159521}, {-2., 1.41421, 2.6444},
{-1., 1.73205, -0.732368}, {0., 2., Null},
{1., 2.23607, 6.73109}, {2., 2.44949, 8.04072},
{3., 2.64575, -0.618051}, {4., 2.82843, -0.228622},
{5., 3., 0.48319}, {6., 3.16228, -43.6138},
{7., 3.31662, 2.14509}, {8., 3.4641, -0.19751},
{9., 3.60555, 1.1845}, {10., 3.74166, 0.187236},
{11., 3.87298, -0.298515}}


Since the sig values are in column 1 of data and the nu values are in column 3, nu can be plotted against sig with

ListPlot[data[[All, {1, 3}]]]


However, I would point out that you can build data much more easily with Table, Mathematica's basic tool for making lists.

data =
Table[
{sig, Sqrt[sig + 4], Quiet @ Check[Tan[sig - (1/sig)*E^(sig)], Null]},
{sig, -15., 11., 1.}]