4
$\begingroup$

I am new to the structure of Mathematica. I understand that in the notebooks, one enters the symbolic expressions and evaluates them. But I need to generate some simulated data and do that a few thousand times within a for loop. Now, do I create separate files like macros or functions that I call from my notebook or do I write my code directly into the notebook?

Thanks!

$\endgroup$
  • $\begingroup$ Please read this thread, starting from this answer. It's better to understand the paradigm beforehand. $\endgroup$ – Dr. belisarius Sep 21 '14 at 17:44
  • $\begingroup$ For loops see the documentation under For[], Do[], While[]. Sample data generation can be done in many ways using random numbers, see RandomReal[] and the "See also " section. $\endgroup$ – Dr. Wolfgang Hintze Sep 21 '14 at 17:44
  • $\begingroup$ Fair enough - thanks for making me aware of the paradigm. It does seem as though one can use Mathematica for the everyday practice of a mathematician. However, is there a good tutorial on writing essays etc. with Mathematica? My grand contribution to this forum will be that I will write an implementation of the Plamen & Koev algorithm for any hypergeometric function of matrix argument following their paper. @belisarius Could you direct me to a post that explains usage of a notebook as a real 'notebook'? Thanks! $\endgroup$ – Hirek Sep 21 '14 at 19:33
  • $\begingroup$ @Hirek Perhaps stackoverflow.com/q/5058854/353410 $\endgroup$ – Dr. belisarius Sep 21 '14 at 19:36
9
$\begingroup$

Ad Hoc Programming: Notebooks

It is very common for programming problems to be solved completely without leaving the confines of a single notebook. A notebook can contain any combination of function definitions and expressions that use those functions. See, for example, the Function Definitions section of the Fast Introduction For Programmers.

The nicest thing about notebooks is that they can contain any mixture of code, prose, graphics, animation, audio and other objects. See How to Create a Lecture Notebook for an example.

Library Re-use: Packages

With increased usage, one might find some functionality has usefulness for more than one notebook. The need arises to store such functionality in a library for reuse. Such libraries are called "packages" in Mathematica. A package can be easily referenced from within a notebook, making all of its functions available to that notebook. See Setting Up Wolfram Language Packages.

Interactive Development Environments (IDEs)

Packages can be authored directly within the Mathematica front-end environment. However, many programmers prefer a more conventional IDE. There is an open-source Mathematica Plugin for IntelliJ IDEA. Alternatively, there is a commercial plug-in for Eclipse called Wolfram Workbench.

Version Control

Notebooks are convenient for improvisational programming tasks, that involve a single developer. They are unfriendly in a collaborative environment involving source control because a notebook acts more like a binary file when it comes to merging. The .m files (or, as of version 10, .wl files) that store packages are simple text files that version well. The IDEs mentioned above have plug-ins to support common version control systems such as SVN or GIT.

How To...

The How To section of the Mathematica documentation is handy for new users. For the present question, see especially the Notebooks and Documents section.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.