When I start up Mathematica and open a Notebook, I usually get a bunch of errors right off the bat. However, when I reevaluate the code (i.e., Shift + Enter), everything works just fine. What’s going on? (Please see attached screenshots below.)
The cell where points1 is defined, has to be an initialization cell, not just a normal cell. An initialization cell will automatically get evaluated when the notebook is loaded.
But I would just rewrite your Manipulate by simply putting the points1=... code inside Manipulate itself, so you do not have to worry about all of this. Simply write Manipulate[.....,Initialization :> (points1=Table[...])] and now everything is in one place.
Forgive me Nasser, this must be so simple, but I just can’t get it to work either way. I tried your second solution first by inputting the points1= code inside Manipulate (see first image below), which gave me an error.
I also tried making the points1 cell an initialization cell (see second image below), but this still didn’t make the code run properly.
I’m just wondering, though, why it didn’t work when I made points: = … into an initialization cell (see image below). Do I have to ungroup it from all other cells? This didn’t seem to work either.
Nasser is incorrect in saying that code in initialization cells are executed on opening the notebook they are in. Upon (manual) evaluation of the first line of code Mathematica offers to evaluate initialization cells first. Only if you agree, and only then, is the initialization code evaluated.
A solution to your problem may be the use of the Manipulation option SaveDefinitions, but you should be aware of the dangers of using it.