Mathematica Debugging Weird Mathematica Behavior

Click For Summary
The discussion centers on issues encountered while using Mathematica for calculations, specifically regarding the inconsistent behavior of subscripts and the use of Goto loops. The initial problem involves the subscript notation, where the term H3 does not consistently read the input value, leading to confusion. A solution suggested is to avoid subscripts unless the user knows how to modify their properties. Additionally, the user faces challenges with Goto loops, particularly in referencing labels placed in different cells. The consensus is that Goto should be avoided due to its potential to create unreadable code, and alternatives such as renaming subprocedures and using function calls are recommended. The conversation highlights the importance of keeping code organized within the same active cell to ensure proper functionality. Clarifications on terminology like cells, subprocedures, and function calls are sought, emphasizing the need for practical examples to aid understanding.
natski
Messages
262
Reaction score
2
Hi all,

I have attached a notebook which I am doing a calculation in. For some reason, Mathematica is acting inconsistently. When I run the calculation for the first time, it usually doesn't work. By that I mean I get the output that you can see in the notebook attached.

You can that the problem is coming from the subscript 3 in the term H3. I can't understand why it doesn't just read the value of H3 I input early on!?

I could just ditch the subscript but I really don't want to because I want to eventually change the subscript 3 for a general integer i and rerun the program for many different i values.

I should also add that sometimes the program runs with no problems despite having changed nothing. Once it runs once OK, then everytime thereafter is OK.

Please can someone explain what on Earth is going on!
 
Last edited:
Physics news on Phys.org
Um sorry but I solved this problem!
 
Avoid the use of subscripts, unless you know how to unprotect the head subscript and change it to type symbol.
 
Thanks for the tip. As a further question, I am trying to use a Goto loop and finding a slight difficulty.

I put a label at the beginning of my notebook and then the Goto at the end and it doesn't work because Goto can't find the Label. Even for simple expressions this happens unless all the equations are on the same line. Is there not a way to use Goto and Label when there are many, many (and so a single line calculation is inconvenient) expressions inbetween them?

Thanks
 
No there is no way to make Goto do what you want.

But if you want to Goto a cell, then it is probably because that cell contains a subprocedure. So why not rename the subprocedure, evaluate the cell which defines it, and replace the Goto with function calls?

In the 1970s it was decided that the use of Goto should be deprecated in all languages, because it leads to poorly readable code. Imagine looking all over the place for someone elses Goto Label. Mathematica compromises by allowing the Goto, but restricting it to be local in the sense you describe.
 
Hmmm I don't really understand what you mean, the terms cell, subprocedure and function calls are not really clear to me. Can you please show me an example?
 
You said that, when working, all your Goto code was on the same line. The imprortant thing is that all your code was in the same active active cell. See the example.

I tried to guess what issues were having, but if you want to talk specifics you should show me your code.
 

Attachments

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 18 ·
Replies
18
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K