2
$\begingroup$

I have been given two functions with an initial condition. One function becomes the variable of the other. I need to run the program for 10 iterations.

d = 100 (initial condition)
x = (300*d)/(d + 100)

Next

d1 = 200 - x 

d1 should become the variable of the function x instead of d.

Again

 x2 = (300*d1)/(d1 + 100)
 d2 = 200 - x2
 x3 = (300*d2)/(d2 + 100)
 d3 = 200 - x3

and repeat the process until 10 iterations have been made.

How can I write a program to carry out this process?

$\endgroup$

closed as off-topic by george2079, happy fish, gwr, Wjx, Bob Hanlon Apr 2 '17 at 20:21

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." – george2079, happy fish, gwr, Wjx, Bob Hanlon
If this question can be reworded to fit the rules in the help center, please edit the question.

3
$\begingroup$
f[y_, x_] := {200 - x, 300 y/(y + 100)}
ic = {100, 150}
nf[n_] := NestList[f @@ # &, ic, n]
TableForm[nf[10], TableHeadings -> {Range[0, 10], {"d", "x"}}]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you very much. it helps a lot. I really needed to display it as a table too. Thank you once again. $\endgroup$ – prasanthi Mar 31 '17 at 21:44
  • $\begingroup$ My goodness: Isn't that my solution (below)? $\endgroup$ – David G. Stork Mar 31 '17 at 22:14
  • $\begingroup$ @DavidG.Stork I am sorry I did not see your solutions. I agree that they use the same strategy. However your use of null rather than the value of the initial x renders your output difficult to interpret. This, I agree, is a trivial difference but I can only express that it was unintentional. I suggest that you raise with OP. I will completely accept change in vote etc. $\endgroup$ – ubpdqn Apr 1 '17 at 0:15
4
$\begingroup$

Let's do two simple pre-computations.

With[{d = 200 - x}, (300 d)/(d + 100)]

(300 (200 - x))/(300 - x)

and

With[{d = 100}, (300 d)/(d + 100)]

150

Then the iteration can be written as

NestList[300 (200 - #)/(300 - #) &, 150, 10]

{150, 100, 150, 100, 150, 100, 150, 100, 150, 100, 150}

$\endgroup$
4
$\begingroup$
f1 = Function[d, 300*d/(d + 100)]  (* your first transformation *)
f2 = Function[x, 200 - x]  (* your second transformation *)
f = f2@*f1  (* your composed transformation *)
(* using NestList *)
NestList[f, 100, 10]
(* using RecurrenceTable *)
RecurrenceTable[{d[n + 1] == f[d[n]], d[0] == 100}, d, {n, 0, 10}]
$\endgroup$
3
$\begingroup$

One could compose the two component function, but another trick is to compute {f1[x], f2[f1[x]}, then take the second component and feed it back as the new x:

Flatten@NestList[
   {temp = 300 #[[2]]/(#[[2]] + 100), 200 - temp} &, 
   {Null, 100}, 10] 

(*

{Null, 100, 150, 50, 100, 100, 150, 50, 100, 100, 150, 50, 100, 100, 150, 50, 100, 100, 150, 50, 100, 100}

*)

I note that I get a different sequence than @corey979.

$\endgroup$
  • $\begingroup$ Yes sequence is little bit different. But thanks a lot for the help. $\endgroup$ – prasanthi Mar 31 '17 at 21:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.