Linked Questions

452
votes
37answers
97k 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 ...
526
votes
19answers
130k 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 ...
177
votes
3answers
39k 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 ...
79
votes
3answers
10k 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 ...
39
votes
8answers
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. ...
10
votes
4answers
33k views

Creating a table/Matrix during a For loop

I have a For loop (with i as a counter), which calculates different values (y1, ...
23
votes
1answer
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 ...
0
votes
2answers
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 ...
4
votes
1answer
1k 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 ...
3
votes
4answers
233 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$. ...
5
votes
2answers
714 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 ...
2
votes
1answer
737 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 ...
1
vote
2answers
111 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 ...
1
vote
1answer
82 views

Cause of loop inefficiencies? [closed]

While I have seen a lot of documentation regarding the inefficiencies of loops in Mathematica, I am still curious as to why-- while I know it is intentionally developed this way to allow for improved ...
0
votes
1answer
134 views

Problems with For statement

I'm trying to iterate some expression through for loop: ...

15 30 50 per page