Items tagged with recursion

Feed

Hi Mapleprimes people and robots,


My question is regarding a recursive sequence.  It can be defined non-recursively as - 


a(r) :=  0.8*3^r + 0.2*(-2)^r.

The first few terms are - 

1,2,8,20,68,188, and so on.

Here is my Maple Worksheet.
recursive_sequence_A133467.mw      recursive_sequence_A133467.pdf

I want some Maple code that will produce 30 terms of this sequence.  It is defined as

s[1]:=1:
s[2]:=2:

for n>2 we let s[n] = s[n-1] + 6*s[n-2].

Let me know if my question does not make sense.

Regards,
Matt

 

How to write procedure to find factorial n? Induction to be used.

 

This is reduced from another forum.

restart;
e1 := 12*g^2+12*h^2+4*i^2+3*j^2=684;
e2 :=  12*l^2+12*m^2+4*n^2+3*o^2=684;
e3 := 12*q^2+12*r^2+4*s^2+3*t^2=172;
e4 := 12*v^2+12*w^2+4*x^2+3*y^2=108;
e5 := 12*g*l+12*h*m+4*n*i+3*j*o=-84;
e6 := 12*g*q+12*h*r+4*s*i+3*j*t=-84;
e7 := 12*g*v+12*h*w+4*x*i+3*j*y=-84;
e8 := 12*l*q+12*m*r+4*n*s+3*o*t=-84;
e9 := 12*l*v+12*m*w+4*n*x+3*o*y=-84;
e10 := 12*q*v+12*r*w+4*s*x+3*y*t=-84;
e11 := g+h+i+j=-1;
e12 := l+m+n+o=-1;
e13 := q+r+s+t=-1;
e14 := v+w+x+y=-1;
e15 := h*i+m*n+3*s*r+4*x*w=-21;
e16 := g*i+l*n+3*s*q+4*x*v=-21;
e17 := i+n+3*s+4*x=-3;
e18 := g*h+m*l+3*q*r+4*w*v=-7;
e19 := h+m+3*r+4*w=-1;
e20 := g+l+3*q+4*v=-1;
e21 := i*j+o*n+3*s*t+4*x*y=-84;
e22 := j*h+o*m+3*r*t+4*y*w=-28;
e23 := j*g+o*l+3*q*t+4*y*v=-28;
e24 := j+o+3*t+4*y=-4;
e25 := j^2+o^2+3*t^2+4*y^2=144;
e26 := i^2+n^2+3*s^2+4*x^2=129;
e27 := h^2+m^2+3*r^2+4*w^2=57;
e28 := g^2+l^2+3*q^2+4*r^2=57;

eqset := {e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15,
          e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28};
for s in eqset do print(s) end do;

Error, too many levels of recursion

If I then do

S := {1,2,3,6,3,6,8,2,3,6};

for s in S do print(s) end do;

Then,

for s in eqset do print(s) end do;

has the correct output.

What am I doing wrong?

Tom Dean

Hi,

Seem to be a bit stuck. Here's my code:
 

Thanks in advance :-) 

Please Sir/Ma, I'm trying to generate a recurrent relations of this series and I try to use "if" "else" condition but I didn't get it right. Any one with useful suggestions. Appreciate 

 

restart;
Y[0] := A; Y[1] := B;
if k = a then delta(k-a) := 1 else 0 end if;
                               0
for k from 0 to 10 do Y[k+2] := solve(add(delta(i-1)*(k-i+1)*(k-i+2)*Y[k-i+2], i = 0 .. k)+add((delta(i)-delta(i-1))*(k-i+1)*Y[k-i+1], i = 0 .. k)+lambda*Y[k] = 0, Y[k+2]) end do;
y := sum(Y[j]*x^j, j = 0 .. 10);
 

I copy a program from a book and try to run it, but when i try to run it return:

too many levels of recursion

Here is my program:

Hope every one can help me solve this problem. Thank!

In Maple V, Release 4 (1996):

 

T:=table():
i:=1:N:=5000;

for i from i to N  
do
   T[i]:=T[i+1]:
   T[i+1]:=1;
   eval(T[1]);
od:
print(i);

for i from i to N  
do
   T[i]:=T[i+1]:
   T[i+1]:=1;
   eval(T[1]);
od:
print(i);

I receive this output:

N := 5000
Error, too many levels of recursion
3607
5001

Can You explain this occurence, as well as the following one:

In Maple V, Release 4 (1996):

 

T:=table():
i:=1:N:=5000;

for i from i to N  
do
  T[i]:=T[i+1]:
  eval(T[1]);
od:
print(i);
 
for i from i to N  
do
  T[i]:=T[i+1]:
  eval(T[1]);
od:
print(i);;

gives:

N := 5000
Error, too many levels of recursion
3607
Error, too many levels of recursion
3607

How does one control allowance for recursion depth?

Given the sequence defined by the recursive relation a[n+1] = r*a[n](1-a[n])
You need to use the procedure iterate.
Throughout this problem you should choose initial values in the interval 0<a0<1.
(a) Let r=3/2. Calculate a moderate number of terms in the sequence (between 10 and 20). Does the sequence appear to be converging? If so to what value? Does the limit depend upon your choice of initial value? Plot the terms you have calculated
(b) Let r=2.8. Calculate a moderate number of terms in the sequence (between 10 and 20). Does the sequence appear to be converging? If so to what value? Does the limit
depend upon your choice of initial value? Plot the terms you have calculated How does this sequence differ from that in part (a).
(c) Let r=3.2. Calculate a moderate number of terms in the sequence (between 10 and 20). Show that the sequence does not appear to converging. Plot the terms you have calculated and describe how the sequence behaves in this case.
(d) Consider intermediate values between 2.8 and 3.2 to determine more precisely where the transition in behaviour takes place. Provide a few plots (no more than 4) showing the values you have investigated.
(e) Consider the values of r in the range 3.43<r<3.46. Determine as accurately as you can the value of r for which the period of oscillation doubles.
(f) As r increase further period doubling occurs. Try to find the when the sequence appears to oscillate between 8 values.
(g) Let r =3.65 and calculate a considerable number of terms (at least a few hundred) and plot your values.
(h) For r=3.65 choose a0=0.3 and then a0=0.301. Find and plot some terms in the sequence for each initial value. Determine how long the terms in the two sequences remain close together and when they begin to depart significantly from each other.

 

Hello,
I have defined a function f (x, e, y).  I give values of n: = i * h as follows:

f (x (n), w (n), t) = w * t * x;
n: = i * h;
r (n) = n;
Then I need to do this operation:
w (n) = w (n) + r (n);

w(n):=15; r(n):=30;

w(n):=w(n)+r(n);

w(n);
Error, (in w) too many levels of recursion.

How i can operate?.

Regards.

 

 

> coth;
                                    coth
> restart;
> c := 0;
                                      0
> w := -2*mu;
                                    -2 mu
> a[-1] := 0;
                                      0
> a[0] := mu*lambda*sqrt(-6*a);
                                            (1/2)
                            mu lambda (-6 a)     
> a[1] := (6*(mu*lambda^2+1))/sqrt(-6*a);
                               /         2    \
                             6 \mu lambda  + 1/
                             ------------------
                                      (1/2)    
                                (-6 a)         
> b[-1] := 0;
                                      0
> b[0] := 0;
                                      0
> b[1] := 0;
                                      0
> xi := x+w*t;
                                 x - 2 mu t
> P := sqrt(-mu)*coth(A+sqrt(-mu)*xi);
                     (1/2)     /         (1/2)             \
                (-mu)      coth\A + (-mu)      (x - 2 mu t)/
> u := a[0]+a[1]*P/(1+lambda*P)+a[-1]*(1+lambda*P)/P+b[0]*sqrt(sigma*(1+P^2/mu))/P+b[1]*sqrt(sigma*(1+P^2/mu))+b[-1]*sqrt(sigma*(1+P^2/mu))/P^2;
                 (1/2)
 mu lambda (-6 a)     

           /         2    \      (1/2)     /         (1/2)             \   
         6 \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/   
    + ---------------------------------------------------------------------
            (1/2) /                (1/2)     /         (1/2)             \\
      (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//
> Diff(u, t)+a*u^2*(Diff(u, x))+Diff(u, `$`(x, 3));
/    /                     
| d  |                (1/2)
|--- |mu lambda (-6 a)     
| dt |                     
\    \                     

          /         2    \      (1/2)     /         (1/2)             \   \\     /          
        6 \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/   ||     |          
   + ---------------------------------------------------------------------|| + a |mu lambda
           (1/2) /                (1/2)     /         (1/2)             \\||     |          
     (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)////     \          

        (1/2)
  (-6 a)     

          /         2    \      (1/2)     /         (1/2)             \   \   
        6 \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/   |   
   + ---------------------------------------------------------------------|^2
           (1/2) /                (1/2)     /         (1/2)             \\|   
     (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)///   

  /    /                     
  | d  |                (1/2)
  |--- |mu lambda (-6 a)     
  | dx |                     
  \    \                     

          /         2    \      (1/2)     /         (1/2)             \   \\   
        6 \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/   ||   
   + ---------------------------------------------------------------------|| +
           (1/2) /                (1/2)     /         (1/2)             \\||   
     (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)////   

  / 3 /                     
  |d  |                (1/2)
  |-- |mu lambda (-6 a)     
  |   |                     
  \   \                     

          /         2    \      (1/2)     /         (1/2)             \   \\
        6 \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/   ||
   + ---------------------------------------------------------------------||
           (1/2) /                (1/2)     /         (1/2)             \\||
     (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)////
> value(%);
                          /                                     2\      
     /         2    \   2 |        /         (1/2)             \ |      
  12 \mu lambda  + 1/ mu  \1 - coth\A + (-mu)      (x - 2 mu t)/ /      
--------------------------------------------------------------------- -
      (1/2) /                (1/2)     /         (1/2)             \\   
(-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//   

                                                                         /   
                                    1                                    |   
  ---------------------------------------------------------------------- \12
                                                                       2     
        (1/2) /                (1/2)     /         (1/2)             \\      
  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//      

                                                                           /
  /         2    \      (1/2)     /         (1/2)             \          2 |
  \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/ lambda mu  \1

                                      2\\     /                     
         /         (1/2)             \ ||     |                (1/2)
   - coth\A + (-mu)      (x - 2 mu t)/ // + a |mu lambda (-6 a)     
                                              |                     
                                              \                     

          /         2    \      (1/2)     /         (1/2)             \   \   
        6 \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/   |   
   + ---------------------------------------------------------------------|^2
           (1/2) /                (1/2)     /         (1/2)             \\|   
     (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)///   

  /                           /                                     2\       
  |       /         2    \    |        /         (1/2)             \ |       
  |     6 \mu lambda  + 1/ mu \1 - coth\A + (-mu)      (x - 2 mu t)/ /       
  |- --------------------------------------------------------------------- +
  |        (1/2) /                (1/2)     /         (1/2)             \\   
  |  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//   
  \                                                                          

                                                                         /      
                                    1                                    |  /   
  ---------------------------------------------------------------------- \6 \mu
                                                                       2        
        (1/2) /                (1/2)     /         (1/2)             \\         
  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//         

                                                                      /
        2    \      (1/2)     /         (1/2)             \           |
  lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/ lambda mu \1

                                         \
                                      2\\|
         /         (1/2)             \ |||
   - coth\A + (-mu)      (x - 2 mu t)/ //|
                                         |
                                         |
                                         /

                                                                       2     
                               /                                     2\      
          /         2    \   2 |        /         (1/2)             \ |      
       12 \mu lambda  + 1/ mu  \1 - coth\A + (-mu)      (x - 2 mu t)/ /      
   - --------------------------------------------------------------------- +
           (1/2) /                (1/2)     /         (1/2)             \\   
     (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//   

                                                                        /       
                                    1                                   |   /   
  --------------------------------------------------------------------- \24 \mu
        (1/2) /                (1/2)     /         (1/2)             \\         
  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//         

                                                    2 /
        2    \   2     /         (1/2)             \  |
  lambda  + 1/ mu  coth\A + (-mu)      (x - 2 mu t)/  \1

                                      2\\   
         /         (1/2)             \ ||   
   - coth\A + (-mu)      (x - 2 mu t)/ // +

                                                                         /   
                                                                         |   
                                    1                                    |   
  ---------------------------------------------------------------------- \84
                                                                       2     
        (1/2) /                (1/2)     /         (1/2)             \\      
  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//      

  /         2    \   2     /         (1/2)             \
  \mu lambda  + 1/ mu  coth\A + (-mu)      (x - 2 mu t)/

                                          2                  \
  /                                     2\                   |
  |        /         (1/2)             \ |       (1/2)       |
  \1 - coth\A + (-mu)      (x - 2 mu t)/ /  (-mu)      lambda/

                                                                     3           
                             /                                     2\            
        /         2    \   3 |        /         (1/2)             \ |        2   
     36 \mu lambda  + 1/ mu  \1 - coth\A + (-mu)      (x - 2 mu t)/ /  lambda    
   - ------------------------------------------------------------------------- +
                                                                           3     
            (1/2) /                (1/2)     /         (1/2)             \\      
      (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//      

                                                                         /   
                                                                         |   
                                    1                                    |   
  ---------------------------------------------------------------------- \36
                                                                       4     
        (1/2) /                (1/2)     /         (1/2)             \\      
  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//      

  /         2    \      (1/2)     /         (1/2)             \       3   3
  \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/ lambda  mu  

                                          3\   
  /                                     2\ |   
  |        /         (1/2)             \ | |   
  \1 - coth\A + (-mu)      (x - 2 mu t)/ / / +

                                                                         /   
                                                                         |   
                                    1                                    |   
  ---------------------------------------------------------------------- \72
                                                                       3     
        (1/2) /                (1/2)     /         (1/2)             \\      
  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//      

                                                        2         
  /         2    \   3     /         (1/2)             \        2
  \mu lambda  + 1/ mu  coth\A + (-mu)      (x - 2 mu t)/  lambda  

                                          2\   
  /                                     2\ |   
  |        /         (1/2)             \ | |   
  \1 - coth\A + (-mu)      (x - 2 mu t)/ / / -

                                                                         /   
                                    1                                    |   
  ---------------------------------------------------------------------- \24
                                                                       2     
        (1/2) /                (1/2)     /         (1/2)             \\      
  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//      

                                                        3        /
  /         2    \   2     /         (1/2)             \         |
  \mu lambda  + 1/ mu  coth\A + (-mu)      (x - 2 mu t)/  lambda \1

                                      2\           \
         /         (1/2)             \ |      (1/2)|
   - coth\A + (-mu)      (x - 2 mu t)/ / (-mu)     /
> simplify(%);
Error, (in simplify/tools/_zn) too many levels of recursion
>
>
>
>
pls help

for a to z1/T1 do ics[a*T1] := [g0(0, a*T1) = r, g0(1, a*T1) = s] end, this loop runs correctly for T1:=1, but gives the too many levels of recursion error for T1<1. In this loop i am inserting equations g0 in a list ics.

During a lengthy computation of mine - done using a well established and scientifically sensible external package - I get a Too many level of recursion error in PDEtools/NumerDenom.

Since it has always worked fine for simpler computation with the exact same code, I am wondering whether, with a bigger bound of the level of recursion, the computation could be succesful.

Which is the max level of recursion than maple allows?

Is it possibile to manually (at one's own risk) raise it, in the same line as raising, for instance, stacklimits kernel option?

I have a nice family of functions of the form:

W:=(p,n,mu,w)->sum(w[k] * (n-k)* mu(n-k),k=1..n)

which can be evaluated for different p's using the operator mu*diff(...,mu)

The recursion begins with p=0 and proceeds using mu*diff(W(p,n,mu,w),mu) = W(p+1,n,mu,w).

Can anybody implement this procedure in Maple

Thank you 

Heaviside2.mw

I am a new user of Maple (Dec 2014).  I am trying to calculate an integral related

to mechanical loss.  Temperature is a variable in the problem (as is time), and if

I use a sinusoidal (sine or cosine) temperature-time relationship, I think all works fine.

A difficulty is that the experiments have two-hour hold times(i.e., 7200 seconds) (followed by 22 hours of sinusoidal temperature variation.)

The experiments run for several weeks or months.

I tried using Heaviside functions to model the hold times.(Constant temperature periods)

Now I am receiving errors such as " Error, (in tools/eval_foo/do) too many levels of recursion..."

Probably the Maple code is crude and/or sloppy. Most of the code is simply the setting of constants in the problem.

I will be grateful for suggestions and comments--the file is attached.  Thank you.  John B

T__2 := 291.4:

T__f := 342.7:

B__f := 1265.:

A__0 := 0.452e-10:

`a__&sigma;` := 1.6072:

`b__&sigma;` := 5.6072:

mu := proc (x) options operator, arrow; .212008+0.21666e-2*x end proc:

t__age := 1800.:

`&sigma;__app` := 3.91:

T__0 := 303.15:

D__0 := proc (x) options operator, arrow; .103172+0.633333e-2*x end proc:

A__ex := B__f*T__f/(T__f-T__2)-`a__&sigma;`*`&sigma;__app`^2:

C__ex := B__f*T__f/(T__f-T__2)-`b__&sigma;`*`&sigma;__app`:

A__00 := A__0*exp(A__ex/T__0):

NULL

NumericEventHandler(invalid_operation = `Heaviside/EventHandler`(value_at_zero = 1)):

tm := proc (t) options operator, arrow; `mod`(t, 86400) end proc:(temperature cycle repeats every 24 hours = 86,400 seconds)

T3 := proc (x) options operator, arrow; (303.15+15.+15*sin((3/2)*Pi+2*Pi*(x-7200)/79200.))*(1-Heaviside(x)+Heaviside(x-7200)) end proc:

F3 := proc (x) options operator, arrow; (Heaviside(x)-Heaviside(x-7200))*303.15 end proc:

ftemp := proc (i) options operator, arrow; evalf(T3(tm(i))+F3(tm(i))) end proc:

C := proc (x) options operator, arrow; A__0*exp(C__ex/ftemp(x)) end proc:

`&tau;__0` := proc (x) options operator, arrow; sqrt(A__00^2*(t__age^mu(ftemp(x)))^2+C(x)^2*x^(2*mu(ftemp(x)))) end proc:

f__0 := proc (z) options operator, arrow; int(1/`&tau;__0`(x), x = 0 .. z) end proc:

g__0 := proc (y) options operator, arrow; D__0(ftemp(y))*exp(f__0(y)^.333333) end proc:

ftim := proc (i) options operator, arrow; 1800.*i end proc:

`&tau;__0`(20);

35860.86195

(1)

f__0(20)

Error, (in tools/eval_foo/do) too many levels of recursion

 

NULL

NULL

NULL

NULL

``

 

Download Heaviside2.mwHeaviside2.mw

I am trying to define some functions by recursion relations but I get this error:

Error, (in type/realcons) too many levels of recursion

Please see the attached file for details:

File.mw

1 2 Page 1 of 2