# Defining iterative algorithms [closed]

Assume the iterative algorithm of interest to be as follows:

Tin = {{-3/4, 1/4}, {5, -6}};
tin = {2/4, 1};
pin = {.7, .3};

(*For initial: first row is Tu, second tu, third pu*)

iterate[{Tu_, tu_, pu_}] := {
l = (tu.tu);
a = Tu.Transpose[Tu].tu.tu;
{{{a, l}, {l + 1, a + 1}},
{a, l^2},
{a, l}}
}


Where the objective is to use the new values of Tu, tu, and pu as derived from the previous iteration as the input values for the next (in this case,

 {{{a, l}, {l + 1, a + 1}}, {a, l^2}, {a, l}}


constitute the input values to be used as Tu,tu,pu for the next iteration, respectively, presented as a list).

Indeed,

Nest[iterate, {Tin, tin, pin}, 1]

{{{{1789/32, 5/4}, {9/4, 1821/32}}, {1789/32, 25/16}, {1789/32, 5/4}}}


Gives us exactly what we are looking for in iteration 1, however:

Nest[iterate, {Tin, tin, pin}, 2]


iterate[{{{{1789/32, 5/4}, {9/4, 1821/32}}, {1789/32, 25/16}, {1789/32, 5/4}}}]

is obviously not what we are looking for (it did not take the new values from the previous iteration as its input, rather it is applying iterate over the correct ordered list

{{{{1789/32, 5/4}, {9/4, 1821/32}}, {1789/32, 25/16}, {1789/32, 5/4}}}


Is there something else I should be doing in this case?

## closed as off-topic by Michael E2, Carl Lange, Bill Watts, m_goldberg, gwrJan 26 at 9:28

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Michael E2, Carl Lange, Bill Watts, m_goldberg, gwr
If this question can be reworded to fit the rules in the help center, please edit the question.

• {{{{1789/32, 5/4}, {9/4, 1821/32}}, {1789/32, 25/16}, {1789/ 32, 5/4}}} is a list of length 1, but the argument pattern for iterate matches a list of length 3, so evaluation is not triggered. Perhaps you have one too many layers of {}. – John Doty Jan 26 at 0:48
• It does seem to be the case that an extra layer of brackets is being evaluated. How would I then, say, make it such that  {{{a, l}, {l + 1, a + 1}}, {a, l^2}, {a, l}} is put out without the additional {} wrapping it? – BayesIsBaye Jan 26 at 1:16
• @Janeiro Multi-line functions in Mathematica should actually be wrapped in parentheses ( ) rather than curly braces { } as curly braces defines lists. – MassDefect Jan 26 at 2:03
• Thank you, I believe that fixed it! – BayesIsBaye Jan 26 at 2:29
• @Janeiro No problem! – MassDefect Jan 26 at 3:00

I believe you have made a simple mistake in defining iterate. Try this:

iterate[{Tu_, tu_, pu_}] :=
Module[{l, a},
l = (tu.tu);
a = Tu.Transpose[Tu].tu.tu;
{{{a, l}, {l + 1, a + 1}}, {a, l^2}, {a, l}}]


Then

Tin = {{-3/4, 1/4}, {5, -6}};
tin = {2/4, 1};
pin = {.7, .3};

Nest[iterate, {Tin, tin, pin}, 2]


gives

{{{10292833394741/1048576, 3203021/1024}, {3204045/1024, 10292834443317/1048576}},
{10292833394741/1048576, 10259343526441/1048576},
{10292833394741/1048576, 3203021/1024}}


Is that the result you expect?