Student Support Forum > General > > "Function recursion doubt"

 Post Reply: Name: Email Address: Please send email when my message is replied to. Url (optional): Subject: Message: view original message? Attachment (optional): Please answer this: 3+1 =

 Original Message (ID '45117') By Bill Simpson: First is a small error and will not fix your problem. At the end of your Module you have -dia]]; tabla]] This should be -dia]]]; tabla] Next is a large error and appears to be the cause of your problem. In your module you have torneo[n/2]; (*here is recursive function When you recursively call torneo[n/2] a new copy of torneo does the calculation and then returns the matrix as the value of the recursive call. You then do nothing with this returned value, you do not use the value to update your matrix, and the result is then discarded. You must decide how to use the value returned from the recursive call. Perhaps you want to use that returned value to modify tabla in your matrix. I cannot be certain. Does this make it clear? This shows an example of recursively creating smaller vectors and then joining the smaller vector to the rest of the original vector. In[1]:= f[n_]:=Module[{tabla}, tabla=Table[0,{n}]; tabla[[n]]=n; If[n>1,tabla=Join[f[n/2],Drop[tabla,n/2]]]; tabla ]; f[16] Out[2]= {1,2,0,4,0,0,0,8,0,0,0,0,0,0,0,16} For a matrix it would be more complex to update the original tabla.