Skip to main content

Questions tagged [procedural-programming]

Questions about Mathematica's procedural programming paradigm.

Filter by
Sorted by
Tagged with
3 votes
3 answers
506 views

I make heavy use of Out in Mathematica's notebook environment. When I get a computation to work, it will often be spread across multiple cells and lines with ...
Diffycue's user avatar
  • 1,973
1 vote
3 answers
229 views

I'm trying to apply two lists random numbers to a list of lists of functions, retrieve a Boolean result for each application, and test for AND coincidence between results. I have a working method, ...
BohemianTapestry's user avatar
1 vote
3 answers
255 views

A GeneralizedDo is supposed to thread over multiple iterators: ...
user13892's user avatar
  • 10.4k
6 votes
7 answers
557 views

Is there any way to make cyclic loop over array without PadLeft,PadRight, ArrayPad? So ...
lesobrod's user avatar
  • 2,590
4 votes
1 answer
216 views

I have an implementation in Mathematica that involves iteratively generating large ranges of values, performing element-wise operations, and calculating a cumulative product followed by a total. While ...
Dotman's user avatar
  • 590
0 votes
0 answers
166 views

Edit: Clarifying the Core Issue i=x; While[Abs[p1 - p2] >= p1 tol, p2 = p1; p1 += s *= i (mkn + i)/((k1 - i) (n1 - i)); i--; ]; The core of my ...
Dotman's user avatar
  • 590
1 vote
1 answer
154 views

I have the following snippet written in Python that I want to run in Mathematica ...
QFTheorist's user avatar
1 vote
1 answer
162 views

My question involves what is often considered to be horrible Mathematica code; that is, code which is essentially procedural involving nested loops, rather than mapping, threading, and so forth. Here, ...
CrimsonDark's user avatar
1 vote
0 answers
129 views

I have a folder containing eg. around 40K txt files with randomly assigned names. I am trying to import the content of these files as List/Table and process them ...
BabaYaga's user avatar
  • 1,957
3 votes
0 answers
96 views

Can somebody explain the behavior of Return inside a function? I know that Function and If ...
Daniel Huber's user avatar
  • 60.9k
0 votes
0 answers
73 views

I call a "pseudo-linear", homogeneous system with m equations positively representable, if it has m terms that are sums with positive coefficients of the others. A class with precisely one &...
florin's user avatar
  • 2,380
1 vote
1 answer
127 views

I'm new to Mathematica and I'm attempting to write an approximation algorithm to compute "maximum" independent sets. What I need to do is given a graph g ...
Leonardo Lovera's user avatar
1 vote
2 answers
188 views

I have a second-order recurrence equation that I want to plot. I've used two different methods. The first uses RecurrenceTable, the second uses a traditional ...
Pascal77's user avatar
0 votes
1 answer
134 views

How can I transpose the following SCILAB/MATLAB code into MATHEMATICA? I took a look at similar questions, but none of them seemed to provide a solution. ...
Pascal77's user avatar
4 votes
1 answer
160 views

I need to create matrix from a large array (>>10000 elements) for further use. I have tried Outer and ParallelTable commands, among which Outer seems to be faster when the array size is not so ...
user91411's user avatar
  • 420
1 vote
1 answer
108 views

I want to run an iteration where at each step I check whether I obtain an error message, and if I do, I want to not store that result and move on to the next iteration instead. Here's an example of ...
juv95's user avatar
  • 403
1 vote
2 answers
125 views

Good morning. Reading some code in a webpage, I found this expression: X[0] = 0.5; (*edited from x to X*) X[n_ /; 1 <= n] := X[n] = Sin[n] X[n - 1] + Cos[n] Is ...
kurush's user avatar
  • 45
6 votes
3 answers
342 views

Consider this code to simulate a simple instance of the coupon collector problem. We initialize an array to {0, 0} and then keep incrementing a random element until we've incremented every element at ...
dreeves's user avatar
  • 746
1 vote
0 answers
164 views

BACKGROUND call/cc is commonly used by lisp-like languages as a control flow operator. And mathematica can also be seen as a lisp-like language. QUESTION How to complete implement ...
Ember Edison's user avatar
0 votes
0 answers
91 views

I want to calculate the global minimum of an equation which has several hundred Sums (I used 300 in this code), but the calculation is very slow. My code is as ...
user43830's user avatar
  • 101
2 votes
6 answers
659 views

I want to find a combination that satisfies all the solutions of the following formula. $$ x_{1}^{5}+x_{2}^{5}+x_{3}^{5}+x_{4}^{5}-x_{5}^{5}=0 $$ $x_{1}$, $x_{2}$, $x_{3}$, $x_{4}$, and $x_{5}$ are ...
Vancheers's user avatar
  • 776
0 votes
1 answer
213 views

I'm converting a code from MatLab to Mathematica. It takes MatLab less than a second to compute it while its more than ten minutes in Mathematica. I was hoping to improve the performance. Here's a ...
Dotman's user avatar
  • 590
1 vote
0 answers
59 views

I have a problem that procedural functions don't work with parallelization, e.g. AddTo and PreIncrement. At first, I thought it ...
Taiki Bessho's user avatar
0 votes
1 answer
88 views

Recently the looping construct Until was added to Mathematica in 13.1, based on the ResourceFunction Until created by Jon Mcloone. I want to make a generalization named NestUntilList. NestUntilList is ...
Peter Burbery's user avatar
0 votes
2 answers
209 views

I would like to see how the graph of the function en[B, i, j, k, p] changes depending on i, j...
Mam Mam's user avatar
  • 1,933
0 votes
0 answers
110 views

I want to generalise the following algorithm to a loop overall possible subsets of the original set. the algorithm has the following form: ver={X41,X42,X43,X44} and ...
Faktor 2's user avatar
2 votes
1 answer
126 views

Suppose I have three (nested) lists A , B and Cmat where ...
geom's user avatar
  • 688
4 votes
3 answers
446 views

How could this piece of code be written in the Table, or as simply as possible? ...
Mam Mam's user avatar
  • 1,933
0 votes
1 answer
151 views

...
supragyan priyadarshinee's user avatar
0 votes
1 answer
170 views

I have a very long code that take an extremely large amount of time. I have been using the While loop, but with each iteration, it gets slower and slower, so I know there has to be a better way of ...
juv95's user avatar
  • 403
4 votes
2 answers
168 views

Lets say there is a random list of expressions : a={Sin[x], Sin[3 x], Sin[4 x], Sin[x], Sin[4 x], Sin[x], Sin [5 x], Sin[3 x], Sin[5 x]} Plot[{a}, {x, 0, 2 Pi}] ...
a019's user avatar
  • 887
2 votes
2 answers
220 views

I have 60 txt files which I want to import them into Mathematica using a Do loop. Each file contains some numbers (more precisely, a list of numbers). I want to put ...
Wisdom's user avatar
  • 1,318
2 votes
1 answer
144 views

I have a differential equation labelled by eq0 and I want to use finite-difference method to solve it. First, I have to set up the system of equations ...
mathemania's user avatar
1 vote
1 answer
419 views

I have to do a lot of calculations that take lot of time, and using a Do loop is simply too long. It is the first time I am using ...
Eurabio's user avatar
  • 33
2 votes
0 answers
189 views

The problem is to find the weights {w1,w2,w3,w4} that satisfy the condition. Which is the fastest and most scalable way (e.g. for 10000 weights) to write this ...
John Matis's user avatar
1 vote
2 answers
160 views

I am trying the following scheme to learn to implement an iteration using Do loop. I tried to implement the same method using for loop but with same errors. I, therefore, turned to the Do loop to ...
Skj's user avatar
  • 19
0 votes
1 answer
93 views

Im new to loops on mathematica,was wondering how could I create a function to loop through a list which finds the index of the smallest value of that list, makes a sublist from index 1 to that ...
SkySystem's user avatar
3 votes
2 answers
143 views

I am trying to use the NIntegrate function to find the difference in the area beneath two 2 dimensional splines (how much area of the river bed was lost or gained from one year to the next) but, I ...
Andrew Bowsher's user avatar
2 votes
2 answers
548 views

I used a for loop to make 4 variables: For[i = 0, i < 4, i++,bi=0] But when I write b0 or ...
Ahmed's user avatar
  • 369
-1 votes
1 answer
99 views

Help me pls write While loop correctly. I have next code: ...
Mam Mam's user avatar
  • 1,933
0 votes
1 answer
171 views

How to find the length of a For loop? Here is a simple example: For[i = 0, i < 4, i++, Print[i]] 0 1 2 3 How to find that there are in total 4 outputs using ...
SciJewel's user avatar
  • 631
6 votes
2 answers
418 views

If I want to add the $2\times 2$ matrix b along the first dimension of a that has $n\times 2\times 2$ dimensions I can do this ...
granular_bastard's user avatar
0 votes
0 answers
77 views

I wrote a program, parallelized it (using ParallelDo[], SetSharedVariable[] etc.), and enjoyed the wonderful speedup. ...
user7427029's user avatar
2 votes
0 answers
120 views

We can type > and select python to insert python external language cell into notebook. Then we can write python code inside it and evaluate it by pressing ...
azerbajdzan's user avatar
  • 32.8k
4 votes
1 answer
246 views

This produces a nice random walk plot: ...
cybervigilante's user avatar
3 votes
1 answer
82 views

I am doing a long calculation where I create a list using Reap and Sow. However, sometimes this calculation gets too wild and I ...
Philipp's user avatar
  • 51
2 votes
1 answer
294 views

Yup, im a newbie, you guessed it. But I have been having fun solving Project Euler problems with Mathematica. I am on problem #8: The four adjacent digits in the 1000-digit number that have the ...
SugarFoot's user avatar
4 votes
4 answers
345 views

First define length-component error (personal term) : This is an error when we want to get n-th component of a list if n is bigger then the length of the list. For example, ...
imida k's user avatar
  • 4,435
2 votes
2 answers
409 views

I am new to Mathematica ,and I am trying to implement this while loop which adds all odd Fibonacci numbers less than or equal to 2 million but it keeps outputting 0 for sum. Any solutions for that? ...
Brotos's user avatar
  • 31
2 votes
1 answer
337 views

I have this simple Do Loop that, for some reason, takes a really long time for $h<\frac{1}{15}$. Why is this so? Is there a more efficient way in programming such a recursion? ...
korni1990's user avatar
  • 307

1
2 3 4 5
8