cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement the recursion with 2 variables included?

hzadonis
New Contributor

Hi,Masters:

  I have a task to calculate a value, which includes 2variables and should be implemented with recursion restate.

  The formula is simple: Fn = Fn-1 * 2+ An         (Given conditions:F0 = 10, A = 1 + til 5)

 

  I implemented the part of “Fn =Fn-1 * 2“ in Q with “5 {x * 2}\ 10”, but I was blocked with the secondvariable. Do you have any comment? Appreciate for you advice.


Thanks

hzadonis

2 REPLIES 2

Nick
New Contributor
given function 'f' defined as:

f:{[F;A]A+F*2}

does this meet your requirement?

q)f\[10;til 5]
20 41 84 171 346

hzadonis
New Contributor
Hi, Nick:
  Thank you. Let me try your method.
  I wrote a function and create a temp table to store array, then use a while loop to calculate values, not smart.

在2020年7月31日星期五 UTC+8 上午11:58:11<Nick> 写道:
given function 'f' defined as:

f:{[F;A]A+F*2}

does this meet your requirement?

q)f\[10;til 5]
20 41 84 171 346