Message Boards Message Boards

0
|
10011 Views
|
9 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Errors when first opening Mathematica notebook

Posted 9 years ago

Hi there,

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.)

Many thanks!

On startup Error

After reevaluating Fixed

POSTED BY: Ilona
9 Replies

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.

POSTED BY: Sjoerd de Vries
Posted 9 years ago

Ahh okay. Thanks for your response! I guess I'll just stick with initializing within the Manipulate function.

POSTED BY: Ilona

You got the order wrong. If you put the Initialization :>... at the end, not first thing, it should work. The Manipulate pattern is this

  Manipulate[   somecode; somecode; morecode; Show[....], 
                        controlVariable,
                        controlVariable, 
                        Initialization :> (...)]

See if it works now.

POSTED BY: Nasser M. Abbasi
Posted 9 years ago

That solved the issue - thanks!

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.

enter image description here

POSTED BY: Ilona

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.

POSTED BY: Nasser M. Abbasi
Posted 9 years ago

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.

What am I missing?

enter image description here

enter image description here

(Thanks so much for your patience!)

POSTED BY: Ilona

It happens if Dynamic Content for the notebook is enabled, so Manipulate starts working on load to present a picture, but

points1 = Table[<snip>, {i,70},{j,70}]

remains unevaluated, as the error message says. It can be fixed be putting

points1 = Table[<snip>, {i,70},{j,70}]

into a separate Initialization cell or by disabling Dynamic Content, of course.

POSTED BY: Udo Krause
Posted 9 years ago

Thanks so much! That really helps. (I didn't know about separating cells.)

POSTED BY: Ilona
Posted 9 years ago

I tried separating the cells, but I'm still getting errors when first opening the notebook. What did I do wrong? (See image below.)

enter image description here

POSTED BY: Ilona
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract