Re: save value in array during loop

• To: mathgroup at smc.vnet.net
• Subject: [mg70498] Re: save value in array during loop
• From: dimmechan at yahoo.com
• Date: Wed, 18 Oct 2006 04:16:29 -0400 (EDT)
• References: <eh20uf\$2nj\$1@smc.vnet.net>

I can't say that I understand completely what you want.

Here is defined function

f[i_] := Solve[x^i == 1, x]

Here is a For-loop which stores in the s list the 4 first prime numbers
and in the V list the roots of x^Prime[i]=1 (i=1,2,3,4).

s = {}; V = {}; For[i = 1, i <= 4, s = AppendTo[s, Prime[i]]; V =
AppendTo[V, f[Prime[i]]]; i++]

s

{2, 3, 5, 7}

x /. V

{{-1, 1}, {1, -(-1)^(1/3), (-1)^(2/3)}, {1, -(-1)^(1/5), (-1)^(2/5),
-(-1)^(3/5),
(-1)^(4/5)},  {1, -(-1)^(1/7), (-1)^(2/7), -(-1)^(3/7), (-1)^(4/7),
-(-1)^(5/7), (-1)^(6/7)}}

Dimitris

schaa at geo.uni-koeln.de wrote:
> Hi there,
>
> I am new to mathematica and I have the following problem:
>
> save a certain value in an array calculated during a loop.
>
> My attempt:
>
> For[i=0,i<=12,
>    rho = i*25;
>    V[[i]] = UserFunction[0.5];
>    i++]
>
> rho has the role of a global variable and is used in several other functions.
> UserFunction stands for a function which in turn calls other functions.
> V is the array of dimension 13 from 0 to 12.
>
> The code above does not work. What needed to be changed to make it
> work?
>
> Thanks a lot
> -Ralf

• Prev by Date: Re: sum of binomials .. bug ?
• Next by Date: Re: sum of binomials .. bug ?
• Previous by thread: Re: save value in array during loop
• Next by thread: Re: save value in array during loop