# Code for an iteration method

As I am new to writing code for Mathematica, I would really appreciate if someone could provide me the code for the following iteration process.

For $x_0\in[1,2]=C$,

$$x_{n+1}=(1-\alpha_n)Sx_n+\alpha_nTy_n,$$ $$y_n=(1-\beta_n)Tx_n+\beta_nSx_n,\quad n\geq0,$$ where $\alpha_n=\frac{n+1}{3n+5}$, $\beta_n=\frac{n+3}{5n+7}$ and $S,T:C\longrightarrow C$ given by $$Sx=x^{\log x}\qquad\text{and}\qquad Tx=\frac{1}{81}\arcsin(x-1)+1.$$ Starting with $x_0=1.5$.

• Welcome to our site, I would like to suggest that first you read our faq and then respond to its suggestions by showing what you have done so far (with examples of your code). Otherwise your question will probably be interpreted as a request for free coding services, which is not what this community is about. – xzczd Jun 26 '18 at 15:24
• thanks for informing – mark haokip Jun 26 '18 at 15:33
• @markhaokip I've seen that you took the closing of your question on math.SE without complaining and even here, you did delete it when you heard that simple "give me the code" questions are off topic. My feeling is that you respect the rules. On the other hand, it is sometimes really hard when you start something new knowing absolutely nothing and your question contains all information to answer it (which is rare). That being said, if it takes one "here is the code" answer to get you started and make you a valuable member of our community, I'm happy to provide it. – halirutan Jun 26 '18 at 16:10
• @halirutan. I eventually was able to code (the first of my Mathematica code) a three step iteration procedure from the code you have provided. Thanks! – mark haokip Jun 27 '18 at 6:54

## 2 Answers

I have seen your question on math.SE and I know how it is when you don't find the right place to ask a question. Consider this a one-time present. If you truly want to learn Mathematica, you need to put in some effort in understanding what's going on here.

Basically, your iteration can be written down almost as you have it:

s[x_] := x^Log[x];
t[x_] := 1/81*ArcSin[x - 1] + 1;
α[n_] := (n + 1)/(3 n + 5);
β[n_] := (n + 3)/(5 n + 7);

x[0] = 1.5;
x[n_] := (1 - α[n - 1])*s[x[n - 1]] + α[n - 1]*t[y[n - 1]];
y[n_] := (1 - β[n])*t[x[n]] + β[n]*s[x[n]];

ListLinePlot[Table[x[n], {n, 0, 10}], PlotRange -> All]


However, the highly recursive nature of this makes it extremely slow. When computing x[n], the calculation will call the x[n-1] several times and it will be calculated over and over again.

You can speed this up using memoization, which remembers what you have already calculated. But you have to take care to call ClearAll[x] when you change the setting of x[0].

To use this, replace the definition for x[n_] with

x[n_] := x[n] = (1 - α[n - 1])*s[x[n - 1]] + α[n - 1]*t[y[n - 1]];


Again, you need to understand what's going on here and carefully look up everything that you don't know. Please check the following posts

and for your next questions, please show what you have tried and what did not work.

• I upvoted this answer both for its rigor and its good will; – yosimitsu kodanuri Jun 26 '18 at 17:24
• it really is a Godsend! thanks so much. – mark haokip Jun 26 '18 at 17:34
• But doesn't this set a precedent for Mathematica as a code-writing service? – Peter Mortensen Jun 26 '18 at 20:54
• @PeterMortensen No, I don't think so. Look at our most favorite question. Wouldn't you agree that it is exactly the same type of question? Why does it have almost 600 upvotes and 6 answers? It shows absolutely no effort and still, it was interesting enough to get extremely detailed answers. So I think, while enforcing the community rules almost all the time, there should be room for exceptions. I made an exception here because it is the first question of the OP, it was clearly written and he accepted that his question should contain effort – halirutan Jun 26 '18 at 21:12
• What you missed is that the OP had already deleted his question after @xzczd's comment. Let's say I had a hunch and I wanted to encourage the OP by giving him this answer. When I review questions and they are of insufficient quality, I often look up the user-profile and check how many questions the user already asked. Someone with 5+ bad questions that got mostly closed had enough time to learn the rules. I try really hard to get the best out of our users and in this case I decided I take the chance and give an answer. – halirutan Jun 26 '18 at 21:19

I'd like to point out that you can also use FoldList to generate the sequence in an iterative fashion.

First some helper function:

T[x_] := 1/81 ArcSin[x - 1] + 1;
S[x_] := x^Log[x];
α[n_] := (n + 1)/(3 n + 5);
β[n_] := (n + 3)/(5 n + 7);
y[x_, n_] := With[{t = β[n]}, (1 - t) T[x] + t S[x]];


This is the iterator: Given an x and an n, it computes the following element of the sequence (which is $x_{n+1}$):

step[x_, n_] := With[{t = α[n]}, (1 - t) x^Log[x] + t T[y[x, n]]]


An now let's use FoldList to iterate 10 times with initial value 1.5:

FoldList[step, 1.5, Range[10]]


{1.5, 1.13421, 1.01165, 1.0001, 1., 1., 1., 1., 1., 1., 1.}