Questions tagged [procedural-programming]

Questions about Mathematica's procedural programming paradigm.

Filter by
Sorted by
Tagged with
1
vote
1answer
36 views

How can I apply code that calculates one element of a list to the whole list?

I have a problem with a while loop in Mathematica. I want to run the whole list "mFromAlice" in the while loop but I dont know how to do that. It works with the first row, which is named x ...
1
vote
0answers
25 views
0
votes
0answers
50 views

Loop function for a list of codes

I have a list of codes that start with importing column D of an excel sheet which has a hyperlink. Then, the code moves onto importing the text version of the hyperlink and further proceeds with ...
0
votes
0answers
47 views

Avoiding Tables, Do and other loop construction

In my work I have a lot of cases, where I should calculate non-listable functions for a quite large number of points. To be more concrete, consider first listable function ...
3
votes
3answers
142 views

How can I get the While function to evaluate two conditions simultaneously?

This is probably a basic question but I'm having trouble in writing a While conditional that evaluate two conditions at the same time. I have the following code. The idea is to generate two random ...
1
vote
2answers
51 views

For loop, use past iteration

So I'm trying to use Newton's method to find the root of a function. The code works, what isn't working is my absolute error calculation. What I need is to subtract my past iteration from the current ...
0
votes
0answers
47 views

Alternative to procedural loop with evaluation of notebooks

very new Mathematica user here. I am struggeling with programming Mathematical-like and would appreciate some guidance. I set up a main notebook which calls various sub-notebooks: ...
6
votes
3answers
404 views

Create variables in a for loop

I am very new to mathematica, but it would be much easier for me to use For loops in order to create variables. My train of thought was simple, but apparantly does not work. Let's say I defined these ...
1
vote
1answer
62 views

Code to generate many Do-loops, where the $i$-th loop has upper bound given by $f(i$)

How do I get Mathematica to run an arbitrary number of Do-loops, where the i-th loop it upper bound given by some function $f(i)$? I badly need help with this. Let's denote the desired code by ...
0
votes
1answer
48 views

RandomReal inside a loop

I want to perform the following series summation: $$\sum_{j=1}^5 \exp\left[{-\beta \, \left(\text{En} + \frac{\Delta \, X}{Num} \right)}\right] \cos{\left(\text{En} + \frac{\Delta \, X \, T}{Num} \...
6
votes
5answers
342 views

Replace elements of a list based on a function

I have a function of k (written in the form of a table/list to get values) for 16 integer values from 1 to 16: f = Table[3*k*k, {k, 1, 256}] I want to replace ...
1
vote
0answers
41 views

How do you stop a For loop from progressing until a condition has been met?

I have a matrix and the generation of a number between 0 and 1 (this number will act as a probability): ...
1
vote
1answer
106 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 ...
2
votes
3answers
177 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 ...
1
vote
1answer
44 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 ...
1
vote
1answer
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 ...
1
vote
1answer
70 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: ...
0
votes
1answer
72 views

Question about for loop

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 ...
8
votes
3answers
672 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 ...
1
vote
2answers
78 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 ...
3
votes
3answers
190 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. ...
2
votes
1answer
28 views

Which condition inside a loop with unknown value in a condition

I have a Which condition inside a loop such as: ...
0
votes
1answer
51 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 ...
-1
votes
1answer
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 ...
1
vote
1answer
70 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: ...
-1
votes
1answer
86 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[1] for this example): ...
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
43 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: ...
5
votes
2answers
163 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 ...
0
votes
1answer
31 views

Do loop and general loop question for updating a variable

My intention with the following code: ...
0
votes
0answers
38 views

RSolveValue, Table and general programming

If I have the following code: ...
1
vote
0answers
38 views
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 ...
1
vote
1answer
38 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), (...
-1
votes
2answers
47 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 ...
0
votes
0answers
25 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 ...
0
votes
0answers
26 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? ...
1
vote
0answers
53 views

Implements the binary-searching style code in functional way

Given that I have a code snippet written in binary-searching way: ...
0
votes
1answer
60 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 ...
6
votes
3answers
511 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 ...
1
vote
0answers
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: ...
1
vote
1answer
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 ...
1
vote
1answer
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 ...
3
votes
2answers
60 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. ...
6
votes
3answers
354 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
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 ...
2
votes
1answer
35 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: <...
3
votes
1answer
33 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: ...
3
votes
2answers
912 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. ...
4
votes
1answer
285 views

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

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

1
2 3 4 5