Message Boards Message Boards

0
|
4860 Views
|
8 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Avoid errors while using RecurrenceTables?

Posted 6 years ago

Hello - I started having errors in notebooks making use of RecurrenceTables. I am running Mathmatica Version - "11.3.0 for Mac OS X x86 (64-bit) (March 7, 2018)",

I have several notebooks making use of RecurrenceTable. These have been working for many months. All of a sudden they stopped working maybe after an update?

I have replicated the error by copy/pasting a RecurrenceTable example from the online help into a new and empty Notebook

The example is

RecurrenceTable[{a[n + 1] == 3 a[n], a[1] == 7}, a, {n, 1, 10}]

The error is - RecurrenceTable::dsvar: 1 cannot be used as a variable.

This is happening for all notebooks new and old that use RecurrenceTables

Any ideas what is going on?

thank you Al

POSTED BY: Albert Cattani
8 Replies

Dear Albert,

try

ClearAll["Global`*"]

That clears the global context. The documentation shows how to clear private contexts.

instead.

POSTED BY: Marco Thiel
Posted 6 years ago

Thank you to Marco and Gianluca for pointing me at the root cause and solution. But I will plead ignorance on how Mathematica is working under the covers. Maybe you can enlighten me or point me to documentation?

I added the Clear[n] to the offending notebook and presto! the problem resolved itself. And yes 'n' was in common between the two notebooks.

Question - I have "ClearAll;" as the first line of all my notebooks. Wouldn't that clear 'n' also?

Question - Where can I read more about how the kernels interact? Specifically how variables are shared across notebooks?

But again thank you both for helping someone still earning.

POSTED BY: Albert Cattani

I suppose that this is not really a matter of "who the heck knows why just be happy it's working again". If you open two notebooks they will use the same kernel unless you explicitly specify using another kernel. That means that variable assignments in one notebook affect the definitions in the second notebook. As Gianluca says, RecurrenceTable does not protect its variable names.

In your case the n was probably somewhere defined to be 1. If you then want to use it as an iterator, it will (before the evaluation) be substituted by the value 1. Then the recurrence table does not have a valid iterator variable and does not work. Once you kill the kernel or clear the variables it will work again.

Cheers,

Marco

PS: If you post the two notebooks we can probably trace the problem down more directly.

POSTED BY: Marco Thiel
Posted 6 years ago

I have found an interesting (yet unexplained) pattern. Maybe someone will have some insight. I have two notebooks call them HAS-RT and NO-RT. HAS-RT has RecurrenceTables

Steps to create errors 1- Open and run HAS-RT all is ok. HAS-RT works as expected. Keep window open 2- Open and run NO-RT and all is ok. NO-RT works as expected. 3 - Immediately after running NO-RT the errors appear in HAS-RT

At this point I can no longer run HAS-RT unless I close all notebooks and kill the kernel

This only happens with these two notebooks. Other notebooks opened along with HAS_RT does not cause this issue.

I do not see any common components between these two workbooks. But somehow NO-RT is stepping on HAS-RT

I also have a ticket open with technical support on this. But if anyone has any idea I would love to hear them

thanks

POSTED BY: Albert Cattani

Killing the Kernel is overkill. It is enough to Clear the variables you are using inside RecurrenceTable, which does not protect its variables:

n = 1;
RecurrenceTable[{a[n + 1] == 3 a[n], a[1] == 7}, a, {n, 1, 10}]
Clear[a, n];
RecurrenceTable[{a[n + 1] == 3 a[n], a[1] == 7}, a, {n, 1, 10}]
POSTED BY: Gianluca Gorni
Posted 6 years ago

thanks .... great minds think alike. I should have thought of killing the kernel sooner

POSTED BY: Albert Cattani

Works fine on my machine:

enter image description here

Have you tried restarting the kernel?

Best wishes,

Marco

PS: Sorry. Your second message came only up after I posted my reply.

POSTED BY: Marco Thiel
Posted 6 years ago

I resolved the issue but I cannot say I understand what happened. Bottom line I had to close all workbooks and then kill the running instance of Mathmatica. Just closing all notebooks did not work.

I will chalk this one up to "who the heck knows why just be happy it's working again"

POSTED BY: Albert Cattani
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