Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'nested loops' topicStudent Support Forum > General > "nested loops"

Next Comment >Help | Reply To Topic
Author Comment/Response
Yee H.
08/12/03 00:45am

I apologize if this is too obvious of a question to ask, but I have spent many hours with the online Mathematica Book trying to figure out the proper way to implement this structure in Mathematica.

For example's sake, I have a list of 10 calculated values, n. I want to make a new list s, where s[[1]] = n[[1]], s[[2]] = n[[1]] + n[[2]],..., s[[10]] = n[[1]] + n[[2]] + ... + n[[10]].

One way to think of it:

n={1,2,3,4,5,6,7,8,9,10};
s={null};

For i = 1 to 10;
x = 0;

For j = 1 to i;
x = x + n[[j]];
Next j;

s={s, x};
Next i;

Flatten{s};

So that list s contains the desired sequence of 10 sums from list n.

I thought I had made up an easy example for myself, to learn about using Mathematica (draw a series of values, calculate their cumulative sums, convert to cumulative frequencies, and plot), but so far it's been very frustrating.

There isn't a library or bookstore near me with a Schaum's outline or other guiding resource, and my school is not in session for me to ask an instructor.

I will be grateful for your recommendations. The Mathematica Do, While, For structures are confusing to me.

Yee

URL: (none),

Subject (listing for 'nested loops')
Author Date Posted
nested loops Yee H. 08/12/03 00:45am
Re: nested loops VL 08/13/03 10:51pm
Re: nested loops Henry Lamb 08/15/03 03:54am
Next Comment >Help | Reply To Topic