0
|
3707 Views
|
|
0 Total Likes
View groups...
Share
GROUPS:

# loop, iterative function....

Posted 9 years ago
 Hello, i created an exercise to understand how to write a loop, iterative function,.... Y={{1,2,3,4,5,6,7}} universal formula: xn=120-e^Yn-an-1 zn=log[xn]*Yn+?xn An=Cos[zn] Step by step is this: X1=120-e^1-0 Z1=log[x1]*1+?x1 A1=Cos[z1] X2=120-e^2-a2-1 Z2=log[x2]*2+?x2 A2=Cos[z2] etc. i want a solution with one command, which give mal all at once. Thank you very much
 As it stands it will not work because it has circular dependencies (setting a === A, otherwise a remains undefined) In:= Clear[x, a, z] z[n_Integer] := n Log[x[n]] + x[n]^(1/3) a[n_Integer] := Cos[z[n]] x[n_Integer] := 120 - Exp[n] - a[n] - 1 In:= z \$RecursionLimit::reclim: Recursion depth of 1024 exceeded. >> If it's decoupled by free will (taking a as different from A and giving a a random definition) and the values of A are searched for it is simply In:= Clear[x, a, z, A] z[n_Integer] := n Log[x[n]] + x[n]^(1/3) A[n_Integer] := Cos[z[n]] x[n_Integer] := 120 - Exp[n] - a[n] - 1 a[n_Integer] := n (* ? *) In:= A /@ Range // N Out= {-0.982096, -0.042459, 0.835536, 0.0925525, 4.94991*10^7 - 2.50804*10^7 I, 2.22449*10^10 + 8.36742*10^9 I, -9.6318*10^12 - 1.82179*10^12 I} no need for a loop. Of course you get out other values too in the same way In:= a /@ Range Out= {1, 2, 3, 4, 5, 6, 7} In:= x /@ Range // N Out= {115.282, 109.611, 95.9145, 60.4018, -34.4132, -290.429, -984.633}