Questions tagged [procedural-programming]

Questions about Mathematica's procedural programming paradigm.

Filter by
Sorted by
Tagged with
57
votes
5answers
6k views

Are there any cases when For[] loops are reasonable?

To my mind the only reason for the existence of For[] loops in Mathematica is to allow new users with some experience in procedural programming languages to write ...
13
votes
3answers
8k views

“do … while” loop equivalent in Mathematica [closed]

Have I missed something or is there no built-in which mimics the behaviour of do ... while loop? I am looking for a construct that evaluates procedure once and ...
2
votes
1answer
192 views

Changing a Part of a variable within ParallelDo

I want to evaluate nested do as a parallel computations. My formula looks like: ...
11
votes
2answers
3k views

How to pass variables by reference and by value [duplicate]

I haven't seen this question specifically addressed before in this site, although some hints and traces have been given, for instance, here: Pass by reference for an option argument Does pass-by-...
13
votes
3answers
602 views

Mimic a procedural, recursive clustering algorithm for site percolation using functional programming

Sorry in advance for my logorrhea: I just want to make sure all of the information is here. Context and Question I am investigating site percolation on a square lattice. I have a working, depth-...
5
votes
2answers
159 views

Code to emulate what excel does in cells

I would like to generate a code which emulate the calculations that are being perfom in columns A and B and row 7 to 12 in the attached first image. The results of those calculations are those shown ...
1
vote
1answer
172 views

While loop (or alternative) to generate list of random submatrices satisfying condition

I'm trying to generate a list of random submatrices with matrix norm 0.1, however I'm getting stuck; currently my code looks like this, where I run over a while loop. ...
2
votes
4answers
182 views

How to generate repetitive graphs?

I need to create several graph for different values of a parameter $h$. The code is the following ...
6
votes
3answers
348 views

How do I modify a symmetric matrix while maintaining symmetry?

I'm trying to figure out how to create a For loop for a symmetric matrix. I have a 5 $ \times $ 5 symmetric matrix consisting of 1's and 0's and I'm trying to ...
2
votes
1answer
414 views

Problem with Label in a Do loop, “nolabel”

Can someone tell me why this code doesn't work and how to fix it ? Thanks. ...
1
vote
1answer
255 views

Break out of ParallelDo

In a parallelised computation, I would like each kernel separately to break out of ParallelDo when it has finished going through the loop once. For a single kernel ...
1
vote
0answers
36 views
1
vote
2answers
264 views

Out of memory in a Do loop

I have the following code: ...
1
vote
1answer
66 views

Iterative loop for a given list

Suppose I have the following list: ...
1
vote
1answer
74 views

General question about programing

If I have the following general excel columns, how could a create a program or loop in which I can generate what I have in column A and Column B as lists. "i" represents row number so that for ...
0
votes
1answer
45 views

Problem with Do Loop and TableForm

The following code is supposed to generate 10 tables based on different calculations for different q: ...
0
votes
2answers
113 views

Beginners problem, Do Loop, Eigenfunction iteration

I am trying to find the first Eigenfunction of the Laplacian (in 1D), i.e. a solution of $$ u''(x)=k u(x)\\ u(0)=u(1)=0 $$ with minimal $k>0$ (in this trivial example, I actually know the analytic ...
0
votes
1answer
205 views

Parallelizing nested for loops

I'm currently computing nested for loops. I count up a few counting variables and compute a value for each set of counting variables, then that value is added to an array. It is a way of adding up ...
0
votes
1answer
74 views

How to write the values of a function after each iteration to a .dat file?

I have a differential equation which I solve numerically using NDSolve to obtain y[x]for different values of t. Example:t=0.00; ...
0
votes
2answers
73 views

Save data from loop each determinate time

I have a Do loop then I want to Save data from this loop each x number of iterations. My Do ...