wolfram mathematica - Unusual Solve[] behavior delay -


for project involved computing bond lengths spectroscopic data, used solve[] solve simple equation unknown. began noticing "unusual" behavior when changed input. specifically, when changed number , solve'd, result answer previously. executing code again, however, gives correct answer; it's there's delay of 1 execution. here's example:

b = (11.09 + del)*2.998*10^10;  c = h*1000*n*10^20/(8 \[pi]^2);  h = 6.62618*10^-34;  n = 6.02204*10^23;  del = 0;  solve[c/b == 0.97959253 r^2, r] 

executing gives

{{r -> -1.24567}, {r -> 1.24567}} 

however, when change del = 0 del = 10 in above block, same answer when execute! when execute block second time, correct answer:

{{r -> -0.903299}, {r -> 0.903299}} 

then, changing del = 10 del = 0 , executing gives:

{{r -> -0.903299}, {r -> 0.903299}} 

and can imagine, executing block second time gives correct answer

{{r -> -1.24567}, {r -> 1.24567}} 

there nothing special 0 , 10, 2 numbers work. it's solve[] block has delay effect...

i'm not sure if quirk of computer (macbook intel) or if it's inherent in solve. tell me if guys same behavior did when running code, , if so, have idea why happening? (i have tried restarting mathematica , running again, , behaves way).

the problem del definition after others del present. therefore, @ time when execute, del still has old value. have 2 choices: either place del assignment on top:

del = 0; b = (11.09 + del)*2.998*10^10; c = h*1000*n*10^20/(8 pi^2); h = 6.62618*10^-34; n = 6.02204*10^23; solve[c/b == 0.97959253 r^2, r] 

or use setdelayed (:=) assignment:

b := (11.09 + del)*2.998*10^10; c := h*1000*n*10^20/(8 pi^2); h = 6.62618*10^-34; n = 6.02204*10^23; del = 0; solve[c/b == 0.97959253 r^2, r] 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -