# Help with maple procedure

#### Mos5180d

##### New member
Having trouble with a procedure simply calculating the first value of n in a sequence for when the total is greater or equal to a value of my choice.

The formula for the sequence is as follows

Sn=(n)(1-(-1)^n)/2

So...
S0=0
S1=1
S2=0
S3=3
S4=0
S5=5... and so on.

Therefore...
Tn0=0
Tn1=0
Tn2=1
Tn3=1
Tn4=4
Tn5=4
Tn6=9
Tn7=9... and so on

Which is (floor(n/2))^2

I feel like the procedure attached seems correct but will not give me the correct answer.
2019 should give the answer 90
Please help

#### Attachments

• 4.3 MB Views: 7

#### ksdhart2

##### Senior Member
The first thing I notice is that you have an off-by-one error. This can be fixed by incrementing n at the beginning of the loop rather than the end. To see why this produces the correct answer, consider:

$$\displaystyle T(3) = \sum\limits_{n=0}^{3} = S_0 + S_1 + S_2 + S_3 = 0 + 1 + 0 + 3 = 4 = 2^2$$

$$\displaystyle T(4) = \sum\limits_{n=0}^{4} = T(3) + S_4 = T(3)$$

$$\displaystyle T(5) = \sum\limits_{n=0}^{5} = T(4) + S_5 = 0 + 1 + 0 + 3 + 5 = 9 = 3^2$$

$$\displaystyle T(6) = \sum\limits_{n=0}^{6} = T(5)+ S_6 = T(5)$$

Thus, for any given n, we have $$\displaystyle T(n) = \text{ceiling}(n/2)^2$$. This means, for instance, that the smallest n for which $$\displaystyle T(n) \ge 17$$ is 9, not 8 as your procedure would give (if it were working correctly that is).

Aside from this, I'm kind of stumped as to why your procedure isn't working. About the only thing I can think of is maybe Maple interprets the (n) bit as saying what precedes it is a function of n rather than being multiplied by n. Try inserting a multiplication symbol in there and see if that fixes things.

• Otis

#### Mos5180d

##### New member
Hello. My version of Maple is very old (some syntax differs), but your procedure example works for me, after changing the code according to ksdhart2's suggestions. That is, I moved n:=n+1, and I inserted explicit multiplication symbols in the assignment line for s.

View attachment 11398

Cheers Ahhhh. That is very annoying that I’ve spent so much time on this just for a tiny error like that haha. Thank you for taking the time to try it out #### Mos5180d

##### New member
The first thing I notice is that you have an off-by-one error. This can be fixed by incrementing n at the beginning of the loop rather than the end. To see why this produces the correct answer, consider:

$$\displaystyle T(3) = \sum\limits_{n=0}^{3} = S_0 + S_1 + S_2 + S_3 = 0 + 1 + 0 + 3 = 4 = 2^2$$

$$\displaystyle T(4) = \sum\limits_{n=0}^{4} = T(3) + S_4 = T(3)$$

$$\displaystyle T(5) = \sum\limits_{n=0}^{5} = T(4) + S_5 = 0 + 1 + 0 + 3 + 5 = 9 = 3^2$$

$$\displaystyle T(6) = \sum\limits_{n=0}^{6} = T(5)+ S_6 = T(5)$$

Thus, for any given n, we have $$\displaystyle T(n) = \text{ceiling}(n/2)^2$$. This means, for instance, that the smallest n for which $$\displaystyle T(n) \ge 17$$ is 9, not 8 as your procedure would give (if it were working correctly that is).

Aside from this, I'm kind of stumped as to why your procedure isn't working. About the only thing I can think of is maybe Maple interprets the (n) bit as saying what precedes it is a function of n rather than being multiplied by n. Try inserting a multiplication symbol in there and see if that fixes things.
Your suggestion looked like it worked! Such a simple error thank you!
My lecturer showed us that in mathematical investigations for discrete dynamical systems that...

T0=0
T1=S0
T2=S0+S1
T3=S0+S1+S2 (T2+S2)... and so on

I should have mentioned that before, I assume it’s just different than algebra and calculus sequences?