Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.1K Views
|
10 Replies
|
1 Total Like
View groups...
Share
Share this post:

Obtaining results in a List?

Posted 4 years ago
POSTED BY: B. Cornas
10 Replies
Posted 4 years ago
POSTED BY: B. Cornas

One of the most important parts of the documentation in Mathematica is the "See Also" (either the drop down menu at the top of the help window or the list at the bottom). If you go to a function that is close, you will likely find what you need quickly. For example if you ask for help for "Total" or "Plus", Accumulate is in Both of the "See Also" dropdowns. Wolfram Research did a good job in organizing this part of the documentation

Regards,

Neil

POSTED BY: Neil Singer
Posted 4 years ago
POSTED BY: B. Cornas

I find that the best way to get help is to use Google (or your favorite search engine). It’s often more useful than poring through the documentation. Chances are, you’re not the first person trying to figure out whatever it is you’re trying to do. For example, searching on “Mathematica partial sums of a series” goes right to Accumulate, and a lot of other good discussion.

POSTED BY: John Shonder
Posted 4 years ago

Great. I think it's a good sign if a language offers a couple of different ways to solve a problem. I'll look into FoldList as well. I am just taking my first steps with WL.

POSTED BY: B. Cornas
Posted 4 years ago

The functional programming way to do it

FoldList[Plus, r]
(* {0, 1, 5, 8, 9, 12, 16, 24} *)
POSTED BY: Rohit Namjoshi
Posted 4 years ago

Thanks a million, Rohit, this really helps. I'll study the guide page you mention.

I had seen Spow and Reap a while ago mentioned in a book. I thought it was quite advanced, so I skipped it over. I will study that too Lots to learn still :-)

POSTED BY: B. Cornas
Posted 4 years ago

This guide page is worth studying.

Using AppendTo

m = 0;
result = {};
Do[AppendTo[result, m = m + r[[i]]], {i, 1, Length@r}];
result
(* {0, 1, 5, 8, 9, 12, 16, 24} *)

Using Sow and Reap, which is more efficient than AppendTo.

m = 0;
Do[Sow[m = m + r[[i]]], {i, 1, Length@r}] // Reap // Last // First
(* {0, 1, 5, 8, 9, 12, 16, 24} *)
POSTED BY: Rohit Namjoshi
Posted 4 years ago
POSTED BY: B. Cornas
Posted 4 years ago

Here is one way

r = {0, 1, 4, 3, 1, 3, 4, 8};
Accumulate[r]
(* {0, 1, 5, 8, 9, 12, 16, 24} *)
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard