Questions tagged [procedural-programming]
Questions about Mathematica's procedural programming paradigm.
354
questions
0
votes
0
answers
47
views
Checking whether a linear homogeneous system with m equations and n>m unknowns, has m unknowns that are sums with positive coefficients of the others
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 &...
1
vote
1
answer
83
views
Make a loop while graph is not empty
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 ...
1
vote
2
answers
118
views
RecurrenceTable vs For loop : they do not give the same results. Why?
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 ...
0
votes
1
answer
88
views
How can I transpose SCILAB/MATLAB code with for loop into Mathematica? [closed]
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.
...
4
votes
1
answer
99
views
Efficient way of creating matrices from a very large array while avoiding singular values
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 ...
1
vote
1
answer
48
views
How do I use Check with Table to skip results that contain error messages
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 ...
1
vote
2
answers
84
views
Is this definition similar to a while loop?
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 ...
6
votes
3
answers
241
views
Incrementing a random element of an array repeatedly
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 ...
0
votes
0
answers
81
views
Implementation of call/cc or its analog in Mathematica
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 ...
0
votes
0
answers
47
views
FindMinimum with many Sums and NIntegrates is very slow
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 ...
2
votes
6
answers
480
views
All solutions that satisfy $ x_{1}^{5}+x_{2}^{5}+x_{3}^{5}+x_{4}^{5}-x_{5}^{5}=0 $
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 ...
0
votes
1
answer
119
views
Performance improvements using Table and Compile
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 ...
1
vote
0
answers
39
views
Parallelization with procedural functions, e.g. `AddTo`, `PreIncrement`, and so on
I have a problem that procedural functions don't work with parallelization, e.g. AddTo and PreIncrement. At first, I thought it ...
0
votes
1
answer
52
views
How make a function NestUntilList that accepts multiple arguments?
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 ...
0
votes
2
answers
133
views
Real-time function graph display
I would like to see how the graph of the function en[B, i, j, k, p] changes depending on i, j...