Message Boards Message Boards

0
|
3771 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

loop, iterative function....

Posted 10 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

POSTED BY: Maik Schröder

As it stands it will not work because it has circular dependencies (setting a === A, otherwise a remains undefined)

In[134]:= 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[141]:= z[3]
$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[142]:= 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[152]:= A /@ Range[7] // N
Out[152]= {-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[153]:= a /@ Range[7]
Out[153]= {1, 2, 3, 4, 5, 6, 7}

In[154]:= x /@ Range[7] // N
Out[154]= {115.282, 109.611, 95.9145, 60.4018, -34.4132, -290.429, -984.633}
POSTED BY: Udo Krause
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract