[Date Index]
[Thread Index]
[Author Index]
Re: simple sequence problem
*To*: mathgroup at smc.vnet.net
*Subject*: [mg74423] Re: simple sequence problem
*From*: "dimitris" <dimmechan at yahoo.com>
*Date*: Wed, 21 Mar 2007 02:44:10 -0500 (EST)
*References*: <etnkfe$gqo$1@smc.vnet.net>
=CF/=C7 traz =DD=E3=F1=E1=F8=E5:
> Hi, this might be a silly question, but how do you do this in mathematica.
>
> x1 == Cos[1];
> x2 == Cos[x1];
> x3 == Cos[x2];
>
> and so on ... ... so basically x(n)= Cos[x(n - 1)]
>
> I want to plot n against x(n). How do you do the code for this type of se=
quence in mathematica?
>I want to plot n against x(n). How do you do the code for this type of seq=
uence in mathematica?
Are you interested in cosine iterations?
In[1]:=
(*change some default settrings*)
s = Options[Plot];
$TextStyle = {FontFamily -> "Times"};
SetOptions[Plot, Frame -> {True, True, False, False}, Axes -> {True,
False}, AxesStyle -> GrayLevel[0.6], ImageSize -> 400, PlotRange ->
All];
(*your function*)
In[2]:=
f[x_][i_] := Nest[Cos, x, i]
In[5]:=
Print["example of application of f"]
f[4*(Pi/7)][10]
In[7]:=
Print["another example of application of f"]
(f[2.][#1] & ) /@ Range[40]
In[20]:=
Show[Block[{$DisplayFunction = Identity}, (Plot[f[x][#1], {x, -Pi,
Pi}, PlotStyle -> Hue[#1/7]] & ) /@ Range[1, 6]],
PlotLabel -> StyleForm["Cosine Iteration", FontSize -> 14],
FrameTicks -> {Range[-Pi, Pi, Pi/2], Range[-1, 1, 1/2]}]
Note that
In[30]:=
(f[#1][100] & ) /@ Range[1., 100, 10]
Out[10]=
{0.739085,0.739085,0.739085,0.739085,0.739085,0.739085,0.739085,0.739085,0.\
739085,0.739085}
because cos(x)=x has a fixed point at x ~ 0.73908513.
In[31]:=
({#1, Cos[#1]} & )[FixedPoint[Cos, 10.]]
Out[31]=
{0.739085,0.739085}
In[12]:=
(*restore original settings of Plot*)
$TextStyle ={};
(SetOptions[Plot,#1]&)/@s;
Best Regards
Dimitris
Prev by Date:
**RE: Using legend with FilledPlot**
Next by Date:
**Re: Normal for Limit : Example**
Previous by thread:
**Re: simple sequence problem**
Next by thread:
** Re: Slots & Ampersands**
| |