Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica problem

  1. Mar 15, 2007 #1
    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: Mar 15, 2007
  2. jcsd
  3. Mar 15, 2007 #2
    Um sorry but I solved this problem!
  4. Mar 15, 2007 #3
    Avoid the use of subscripts, unless you know how to unprotect the head subscript and change it to type symbol.
  5. Mar 15, 2007 #4
    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?

  6. Mar 16, 2007 #5
    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.
  7. Mar 16, 2007 #6
    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?
  8. Mar 16, 2007 #7
    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.

    Attached Files:

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook