Re: iterative method?
- To: mathgroup at smc.vnet.net
- Subject: [mg95735] Re: [mg95699] iterative method?
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Sun, 25 Jan 2009 21:50:07 -0500 (EST)
- References: <200901251151.GAA00605@smc.vnet.net>
- Reply-to: drmajorbob at longhorns.com
If you've written Mathematica code and are trying to explain it, why not copy/paste it into e-mail so that we have it right??? Highlight the code, select Edit>Copy As>Plain Text and paste into e-mail. (This works for almost everything.) Asspming I've read your post properly, here's a possible solution for {a,b,c,d}={.1,.2,.3,.4}: Clear[f] f[a_, b_, c_, d_][{x_, y_}] := {(b + a x)/(c x), d x y} pairs = NestList[f[.1, .2, .3, .4], {2, 5}, 50]; Now this plots the x values: ListPlot@pairs[[All, 1]] This plots the y values: ListPlot@pairs[[All, 2]] and this plots both at once: ListPlot@Transpose@pairs Warning: if a, b, c, d are undefined or exact (but not integers), the x and y values get complicated. For instance, this is nestng only TEN deep, not 50, and I've added Simplify to each step: Clear[f] f[a_, b_, c_, d_][{x_, y_}] := Simplify /@ {(b + a x)/(c x), d x y} pairs = NestList[f[Pi, E, Log[10], Sqrt[5]], {2, 5}, 10]; Last@pairs {(2 \[Pi]^10 + E^5 Log[10]^4 (5 \[Pi] + Log[100]) + E \[Pi]^8 (\[Pi] + Log[1000000000000000000]) + E^4 \[Pi]^2 Log[ 10]^3 (20 \[Pi] + Log[1000000000000000000000000000000]) + E^3 \[Pi]^4 Log[ 10]^2 (21 \[Pi] + 4 Log[1000000] + 2 Log[100000000] + Log[1000000000000000000000000000000]) + E^2 \[Pi]^6 Log[ 10] (8 \[Pi] + Log[100000000000000000000000000000000000000000000000000000000])\ )/(Log[10] (2 \[Pi]^9 + E^5 Log[10]^4 + E^3 \[Pi]^3 Log[ 10]^2 (15 \[Pi] + 4 Log[1000000] + 2 Log[100000000]) + E^4 \[Pi] Log[10]^3 (10 \[Pi] + Log[10000000000]) + E \[Pi]^7 (\[Pi] + Log[10000000000000000]) + E^2 \[Pi]^5 Log[ 10] (7 \[Pi] + Log[1000000000000000000000000000000000000000000]))), (1/( Log[10]^8 Log[100])) 31250 (2 \[Pi]^9 + E^5 Log[10]^4 + E^3 \[Pi]^3 Log[ 10]^2 (15 \[Pi] + 4 Log[1000000] + 2 Log[100000000]) + E^4 \[Pi] Log[10]^3 (10 \[Pi] + Log[10000000000]) + E \[Pi]^7 (\[Pi] + Log[10000000000000000]) + E^2 \[Pi]^5 Log[ 10] (7 \[Pi] + Log[1000000000000000000000000000000000000000000]))} And here's another example: Clear[f] f[a_, b_, c_, d_][{x_, y_}] := FullSimplify /@ {(b + a x)/(c x), d x y} pairs = NestList[f[a, b, c, d], {2, 5}, 20]; Last@pairs {(a^19 (2 a + b) + 2 a^17 b (19 a + 9 b) c + 34 a^15 b^2 (9 a + 4 b) c^2 + 80 a^13 b^3 (17 a + 7 b) c^3 + 455 a^11 b^4 (8 a + 3 b) c^4 + 2002 a^9 b^5 (3 a + b) c^5 + 858 a^7 b^6 (7 a + 2 b) c^6 + 264 a^5 b^7 (13 a + 3 b) c^7 + 165 a^3 b^8 (6 a + b) c^8 + 10 a b^9 (11 a + b) c^9 + 2 b^10 c^10)/(c (a^18 (2 a + b) + a^16 b (36 a + 17 b) c + 8 a^14 b^2 (34 a + 15 b) c^2 + 35 a^12 b^3 (32 a + 13 b) c^3 + 91 a^10 b^4 (30 a + 11 b) c^4 + 143 a^8 b^5 (28 a + 9 b) c^5 + 132 a^6 b^6 (26 a + 7 b) c^6 + 66 a^4 b^7 (24 a + 5 b) c^7 + 15 a^2 b^8 (22 a + 3 b) c^8 + b^9 (20 a + b) c^9)), (1/(c^19)) 5 (a^18 (2 a + b) + a^16 b (36 a + 17 b) c + 8 a^14 b^2 (34 a + 15 b) c^2 + 35 a^12 b^3 (32 a + 13 b) c^3 + 91 a^10 b^4 (30 a + 11 b) c^4 + 143 a^8 b^5 (28 a + 9 b) c^5 + 132 a^6 b^6 (26 a + 7 b) c^6 + 66 a^4 b^7 (24 a + 5 b) c^7 + 15 a^2 b^8 (22 a + 3 b) c^8 + b^9 (20 a + b) c^9) d^20} Bobby On Sun, 25 Jan 2009 05:51:27 -0600, matt <trex1704 at yahoo.com> wrote: > How to find x_(n+1)=(a*x_n+b*y_n)/c*x_n , y_(n+1)=d*x_n*y_n using > mathematica? > I want to find a list of x and y when n=1,2,...,50 > so I defined the function as f[{x_,y_}]:={a*x_n+b*y_n)/c*x_n,d*x_n*y_... > } > and then use the function NestList[f,{2,5},50] with initial value of x > is 2 and y is 5 > with this, I got the list of 50 values of (x,y). > The problem is I want to plot graphs of x against n and y against n, n > from 1 to 50 because I want to see what happened if n goes to infinity. > But if use the method I just mentioned, I can only plot x against y. > So do anyone have a clever method?? > Btw...a,b,c and d are constants and given and x_n is supposed to be x > (subscript n)...same case with x_(n+1) and the others > -- DrMajorBob at longhorns.com
- References:
- iterative method?
- From: matt <trex1704@yahoo.com>
- iterative method?