Group Abstract Group Abstract

Message Boards Message Boards

Avoid errors while using RecurrenceTables?

Posted 8 years ago
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 8 years ago
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 8 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 8 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 8 years ago
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