101k views

What are the most common pitfalls awaiting new users?

As you may already know, Mathematica is a wonderful piece of software. However, it has a few characteristics that tend to confuse new (and sometimes not-so-new) users. That can be clearly seen from ...
134k views

Where can I find examples of good Mathematica programming practice?

I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
40k views

Alternatives to procedural loops and iterating over lists in Mathematica

While there are some cases where a For loop might be reasonable, it's a general mantra – one I subscribe to myself – that "if you are using a ...
12k views

Why should I avoid the For loop in Mathematica?

Some people advise against the use of For loops in Mathematica. Why? Should I heed this advice? What is wrong with For? What ...
3k views

Can this be written well, without loops?

Inspired by this question I would like to know if the following code can be written without explicit loops (For, While, etc.) in a clean, efficient and non-contrived way. I have been unable to do so. ...
34k views

Creating a table/Matrix during a For loop

I have a For loop (with i as a counter), which calculates different values (y1, ...
4k views

Error checking and trapping techniques with Throw and Catch

Mathematica provides several mechanisms for checking arguments and trapping errors in a function definition. Typical methods are : Definitions with argument patterns, definitions with ...
3k views

Why function cannot be defined inside For loop? [closed]

I have a following code (which is simplified version of what I am doing): For[i = 1, i <= 5, i++, f[x_] := Sin[x]^2 Print[{i, f[i]}] ] And the question ...
2k views

Creating Functions in a Loop [duplicate]

I am trying to create a list of functions in a loop, using a list of parameters as input to the functions. However, after assigning the each of the functions to the array, when evaluating the ...
241 views

Precision problem with numerical solution of a differential equation

I want solve $$2\sqrt{|\gamma|}x = \int_{1}^{t} dy \sqrt{\frac{1+2|\gamma_2|y}{y^2(1-y)}}$$ where $0<t\leq$1. I'm using a for cycle to evaluate t, calculate the integral and the assign the $x$. ...
729 views

TemporalData, RandomFunction, Loops: Extracting data from TemporalData sets?

I'm doing a finance project for my differential equations class to explore stochastic processes. I'm exploring IRA retirement funds. From the project write-up: Standing assumption: at time of ...
741 views

How to use NDSolve to track a deviation from equilibrium?

i have a task to find a event, to achieve this i think need to integrate until a constant function suddenly breaks the equilibrium and give a sharp peak. I think that EventLocator should work, thus ...
114 views

How can I use /. in a For loop [closed]

I have a huge table of data which I need to insert all of them in my main function using a For loop. For example, I have ...