# Questions tagged [procedural-programming]

218 questions
Filter by
Sorted by
Tagged with
99 views

### Translating pseudocode for the Jacobi algorithm into Mathematica

Here is an image for the Jacobi algorithm. I have almost no knowledge of Mathematica, the textbook does not help. Does not provide examples. The class average is 64%. I just want to be able to ...
175 views

### Re-writing code chunk using While loop

I can't seem to wrap my head around the syntax for how to rewrite this chunk of code I have using a while loop, and would appreciate some help. I'm going through a list and am grouping the values into ...
42 views

### How to use syntax instead of double for loop

I would like to find the distance between a point list (i.e dalist) and list of centers (i.e framecenters). I used the following ...
78 views

### Question about the test format applied in a for loop

I have an issue with the following code. I am trying to remove the points which have a distance less than 2mm relative to each other starting with a specified point ...
68 views

### Issue with Do command

How can I substitute the arrays of a list to the frameCenter1 variable in the following Do loop? I used frameCenter1[[i]] but no answer. Assume frameCenter1 can be selected from this list: ...
69 views

How can I get the results of a "for" loop for each iteration? For example, I have the following for loop and would like to know how I can get the value of S1 for each i value in the output. Also, I am ...
652 views

### How can I replace a set of Nested For Loops with a Functional Code Alternative?

Despite having looked over various posts concerning optimizing nested For loop expressions into a functional programming equivalent I still can not figure out how to actually to do this. Such ...
77 views

### How to run 1000 examples of matrices

I have two functions of matrices, let say $f(A,\,B)$ and $g(A,\,B)$, where $A,\,B$ are positive semidefinite matrices. I want to check if $f(A, B)$ is greater than $g(A,\,B)$ for any $A,\,B > 0$. I ...
174 views

### For Loop to Sum numbers in a list

I'm asked to create a For[] loop that will sum positive numbers in a list. I am unsure of how to do this. ...
26 views

### Which condition inside a loop with unknown value in a condition

I have a Which condition inside a loop such as: ...
50 views

### Do with variables from a table

I want to perform a Do command with n variables, where n is set elsewhere in my code. How do ...
60 views

### List with not computed numbers in Do loop

If I have a a Do loop such as: Do[ list=AppendTo[tts, otherlist] ]//Print,{j,1,10,1} which generates a list of 10 numbers for ...
68 views

### Using a condition in a do loop

If I have the following code which was written by @creidhne here Problem using TableForm and Do loops: ...
84 views

### Problem using TableForm and Do loops

The following code is supposed generates a table based on different calculations for a given q (e.g. q for this example): ...
45 views

### Problem with Do Loop and TableForm

The following code is supposed to generate 10 tables based on different calculations for different q: ...
41 views

### Current iteration number in “do” command

How can I obtain the current iteration number of the "Do" command? For example I want $N$ to be my iteration number in the following command: ...
157 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 ...
28 views

### Do loop and general loop question for updating a variable

My intention with the following code: ...
37 views

### RSolveValue, Table and general programming

If I have the following code: ...
35 views

### General question about RSolveValue and general programming

If I have the following code: ...
74 views

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 ...
36 views

### Loop to match five point differentiation formula

I have a uniform grid (x,y) and I need help to generate a loop to compute (x-2h,y), (x-h,y),(x+h,y),(x+2h,y) for every point of x, and the same thing for every point of y , (x,y-2h),(x,y-h), (x,y+h), (...
45 views

### If statement inside a for loop to find a function?

I am trying to find the value of two functions with two variables by using for loop. Then I want them to satisfy a condition and if that holds then I want to write only those sets of the variables for ...
21 views

### Conditional Loops with Random Samples

I would like to simulate the following process: Pick a random number between 0 and 1. Choose a final time $t_f$. Evolve a (complicated) function $f[t]$ from $t=0$ with small timesteps $\delta t$ (the ...
24 views

### Access a variable outside a loop

If the variable "avrami1" is a column with ten elements (array of 10*1), how can I access the variable "avrami1" outside the loop and get those same ten elements? ...
53 views

### Implements the binary-searching style code in functional way

Given that I have a code snippet written in binary-searching way: ...
52 views

### How can I modify the code to speed up the Do?

I need to use the following code to do some calculations. But the running speed of this code is too slow. How can I modify this code to improve the running speed? ...
36 views

### Load multiple csv files and do iterative calculation for each file

I am trying to read multiple csv files and want to plot them all together, Lets say I have 3 files, file1 , file2 and file3 I want to average 3 files, and plot them all together, So far I have set ...
508 views

### How to terminate a loop when the length of a list reaches a certain length?

If I start out with a list A with $n$ elements in it, how do I append elements to it until it has a length $N$? For example if ...
29 views

### Error while exporting multiple files

I have two questions. I am trying to export results from my calculation when I iterate. I am processing multiple files using code below: ...
30 views

### Can I sample from a distribution whose parameters depend on the current iteration?

Let's say I want to sample from 100 Beta distributions, and in each successive one, the first parameter increases by 1. So given a current iteration number n, I ...
33 views

### Get all step values from a while-loop

I did a loop (first of my life) for an iterative calculation. Is it possible to get all step values as a matrix. That means the "xValue" variable should be like {215.108,219.688,...} and not only the ...
55 views

### What's wrong with While? Is it possible to use double While in a single code input? [closed]

I am supposed to get 2 in the output, but it is still -3 instead. ...
346 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 ...
437 views

### Implementing “do this, then return that” in function definitions

In Python, I often use local variables in defining functions, like so: def f(x): k = initialk < 'do something to k' > return(k) I would like to do ...
34 views

### Getting general::write error while making list in for loop [closed]

So I solved following ODE $$\frac{d^2y}{dx^2}+(a^2 (5+4\tanh( x))+b^2)y=0$$ in Mathematica. Now I need to create a list for further manipulation using the above solution. I wrote the following code: <...
31 views

### More efficiently access iterator values in subkernels?

I'm looking for more efficient ways of observing values in loops in subkernels. For example, take a standard Do loop: ...
908 views

### Improve speed with a double for loop

I am trying to calculate the Euclidean distance of pairs of points $(x_i,y_i)$ with $x$ and $y$ given as separate lists. ...
283 views

### An efficient way to evaluate this expression with deeply nested Do loops

Is there an efficient way to evaluate something like this? ...
44 views

### How to deal with procedurally generated rules and patterns?

I'm trying to procedurally generate replacement rules of the following form ...
40 views

### How to use module to assign functions to a set of imported text files?

I have a lot of text files in my folder (in this example I'm using only 8). I am trying to import all of them and then do calculation on each individual file; I want to use the same notebook without ...
44 views

### Can I use StringReplace to write the number of row which I am replacing?

I have a text file which I have constructed as ...
54 views

### help with improving my code

I am fairly new to MMA-12 and have written the following code to calculate possible coordinates (for given constraints [see If[]] in the code) and get the ...
58 views

### Stop (Parallel)Table evaluation when wanted case is found

I have to go through a long list of evaluations, for which I suppose Table instead of For or ...
239 views

### While loop in a function

f[n_] := ( While[n < 10, n = n + 1]; n ) I am trying to learn mathematica on my own. I am trying to write a function that contains a while loop, but I ...
60 views

### For loop and predefined functions

I tried to write a function which is basically given by a for loop and some predefined functions. I checked already that all of the predefined functions are working, but somehow my for loop does not ...
46 views

### How to do loop with parameter steps [closed]

How to do loop with parameter steps For example I want print numbers : 1,2,4,8,16 but I don't know how to do loop code like this doesn't work Do[ Print[i] , {i, 1, 10, i}]
121 views

### Iterating with Do rather than NestList

This code below works fine for me. ...