Skip to main content

Questions tagged [code-review]

This tag is intended for the review and improvement of style for already functioning code. It not meant to change the objective of the code.

74 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
47 votes
0 answers
3k views

Fast Spherical Harmonics radiative transfer

This is a rather specific question and I apologize for spamming you with some lengthy code. But it could be interesting for some reader and maybe you can help out, so please bear with me. I am using ...
Markus Roellig's user avatar
5 votes
0 answers
208 views

What do “Analyze Notebook" and "Analyze Cells" Do?

What does "Analyze Notebook" and "Analyze Cells" do? They seem to, at least, point out some coding errors that are already highlighted in a notebook. Do they do anything else? Is ...
Just Some Old Man's user avatar
5 votes
0 answers
108 views

Techniques in debugging with preview of possibly large expressions + garbage collection issues

First of all, all appreciate all suggestions how to rephrase the title to make it more friendly. Here's the background: Let's say your top level procedure flow is complicated, involves url calls, ...
Kuba's user avatar
  • 137k
4 votes
0 answers
1k views

Wick Contractions; help with a piece of code

An alternative title to this thread could be, understanding another person's code. A few years back there was a workshop on Mathematica and applications to theoretical physics; if you want I can ...
user avatar
4 votes
0 answers
369 views

Problem with the accuracy of the real-coded Genetic algorithm

Since there is no Genetic algorithm implemented in the Mathematica i tried to write a very simple genetic algorithm myself. The accuracy of the results depend upon rounding up the obtained parameters. ...
user49047's user avatar
  • 791
4 votes
0 answers
851 views

Code Review: ECDSA for Mathematica

The code below contains functions related to ECDSA (Elliptic Curve Digital Signature Algorithm) with standard parameters secp256k1. The implementation is based on ...
Mark Messa's user avatar
4 votes
0 answers
404 views

Better way to compute triple (or higher order) convolution

I have an identity that I want to verify: $$\sum_{i+j+k\ge 2}\binom{n}{i,j,k}{B_{N,i}B_{N,j}B_{N,k}}=\left(\frac{2N^2+n^2-3nN}{2N^2}\right)B_{N,n}+\left(\frac{3n^2-2n-4nN}{2N^2}\right)B_{N,n-1}+\...
Eleven-Eleven's user avatar
3 votes
0 answers
109 views

Placing shapes along a square spiral

Proposed code example is inspired by the main idea of this challenge. Wolfram Language provides great opportunities in computational geometry. But not all of them are equal in terms of speed and ...
lesobrod's user avatar
  • 1,759
3 votes
0 answers
108 views

Sowing Once into Each of Many Lists – Any Better than Append?

In general I know to try to use Reap and Sow over Append or AppendTo due to superior performance. However, Reap and Sow are notorious for being difficult to understand how to use and how they work ...
Just Some Old Man's user avatar
3 votes
0 answers
257 views

Robust PCA (better Mathematica style)

I've parsed (almost verbatim) Python RPCA implementation to WM. Can it be rewritten using a better WM style? In particular, I'm not happy with ...
I.M.'s user avatar
  • 3,081
3 votes
0 answers
141 views

a "Calculate" button for Manipulate with Locator points

Looking for a methodology where the user can move the points of a Locator and then click a button to ask for calculations to proceed. The motivation for this is that the calculations of the full ...
user6546's user avatar
  • 1,069
3 votes
0 answers
76 views

What are some ways to overload Min in order for it to work with user defined expressions?

I have defined size to work with discrete size labels: ...
yosimitsu kodanuri's user avatar
3 votes
0 answers
913 views

Quasinormal modes with Mathematica

I want to compute the quasi-normal modes for the Kerr-AdS black hole, so basically after decoupling the angular and the radial equation, I have troubles to compute the separation constant and also the ...
Julian's user avatar
  • 31
3 votes
0 answers
562 views

Nonlinear FEM and FindRoot

I'm trying to develop a kind of nonlinear FEM application using mathematica to solve a bvp like the following: $$ \gamma(u') ~u^{iv} + 2 \gamma'(u') u''' u''+ u''^3 = f(x) $$ where $u = \tilde{u}(x)...
Petrus's user avatar
  • 397
2 votes
1 answer
57 views

Solving multivariable equation after setting partial derivative to zero

I have a real-valued function of four variables, namely $L[\phi, m0, m1, m2]$. I am interested in taking the partial derivative $\partial_{\phi}L$ thereof and setting the partial derivative to zero, ...
John Doe's user avatar
  • 271
2 votes
0 answers
134 views

Package for static Mathematica code analysis to produce a Cayley tree?

I am looking for a package which can display a static dependency tree of code from a single Mathematica notebook or from a list of Mma notebooks. (Of course, to prevent such a tool from producing tons ...
Adalbert Hanßen's user avatar
1 vote
0 answers
58 views

Why is GraphPropertyDistribution[.] taking an infinite amount of time to run?

This code is from the documentation: ...
Tugrul Temel's user avatar
  • 6,233
1 vote
0 answers
55 views

Why this code does not show three legend lines?

My code shows empty legend lines. What should I do to show the graph with three legend lines? ...
Irram Riaz's user avatar
1 vote
0 answers
164 views

How to show the limit of two functions in a code approach zero?

I don't know how to shorten the program, the entire code is required to understand everything: ...
Arbuja's user avatar
  • 71
1 vote
0 answers
117 views

How to fix Mathematica crashing in the following case?

I have a problem with Mathematica when trying to glue two tables together. The tables have the form ...
John Taylor's user avatar
  • 5,863
1 vote
0 answers
106 views

Code review of my animation of Ellipsoid method

Feel free to suggest improvements (code-review) to my two functions (calculation and animation). They were made to visualize the workings of the Ellipsoid method in two dimensions. For example, see ...
Vepir's user avatar
  • 622
1 vote
0 answers
95 views

Shortest paths Knights Tour

I am trying to print the minimum steps needed to traverse a chessboard as a knight from one diagonal position to the other. I have the following code: Building the chessboard I started with creating ...
Brandon Evans's user avatar
1 vote
0 answers
119 views

Implementing the Binary GCD algorithm in Mathematica

Well, I have $n\in\mathbb{N}$ and I want to transform $n$ to a binary number which can be done using FromDigits[IntegerDigits[n, 2]]. I want to compute the ...
Jan Eerland's user avatar
  • 2,001
1 vote
0 answers
167 views

Algorithms or Mathematica definition for functions ideals of polynomial Rings

This question was well posed four years ago without answer at Operations on ideals of polynomial rings. I asked again in Nov 2021 and posted possible function defininitions. Lichtblau commented ...
crabtree's user avatar
1 vote
0 answers
50 views

Should this Dataset be Transposed for best Neural-Net Performance?

I've been working with this Kaggle dataset and intend to use it to make some time-series predictions from it. I've preprocessed it to the point where now I need to start making some decisions about ...
BBirdsell's user avatar
  • 1,206
1 vote
0 answers
87 views

Integrating an Interpolating Function While Using MaxValue

I have code meant to calculate the following integral, $I_{c}(B_{y},B_{z})=\underset{\phi'}{\text{Max}}\int\limits_{-a/2}^{a/2}\int\limits_{0}^{b}\sin(\phi'+yB_{z}+zB_{y}+\phi_{0}(y))\mathrm{d}y\...
user76078's user avatar
1 vote
0 answers
80 views

FactorInteger snippet works, but use of Sow/Reap/Print is clunky

This is a code review or de-clunking request. If it doesn't belong here, I'll withdraw it. The below toy works and produces the proper output, that is, for numbers to be factored that can be expressed ...
Rabbit's user avatar
  • 701
1 vote
0 answers
102 views

how do I embed a Manipulate expression into my personal website

I have a number of Manipulate[...] codes that I like to embed to my personal website. But I face a problem. Here is a simple example of what I do (my ...
Tugrul Temel's user avatar
  • 6,233
1 vote
0 answers
50 views

General question about RSolveValue and general programming

If I have the following code: ...
John's user avatar
  • 471
1 vote
0 answers
44 views

how to get rid of unintended space between letters

I am facing a terrible problem with Mathematica. I have a very large system of equations to solve. The code works just fine, but when I exit Mathematica and then ...
Tugrul Temel's user avatar
  • 6,233
1 vote
0 answers
426 views

Sum over cyclic permutation of indices

To define the Schouten bracket I need to be able to sum over a cyclic permutation of the indices: $$ [\Phi,\Xi]_S=\mathfrak S_{i,j,k} \left(\Phi^{is}\partial_s\Xi^{jk}+ \Xi^{is}\partial_s\Phi^{jk}\...
Anne O'Nyme's user avatar
1 vote
0 answers
77 views

I have code which is giving me results. I want to improve the code

...
acoustics's user avatar
  • 1,709
1 vote
0 answers
367 views

Problem with Wick Contraction

I'm trying to compute wick contractions knowing that: $\langle a_a a_b \rangle = \delta_{ab}$. So far I've the following ...
Jasimud's user avatar
  • 119
1 vote
0 answers
46 views

understanding en fixing the error in DSolve system

Why does this code not work: ...
Looper's user avatar
  • 287
1 vote
0 answers
64 views

Speed up for SequencePredictorFunction?

From Google Dive: SequencePredictorFunction is here, along with my test data. From pastbin: prediction function and data is here. Using the ...
Chen Stats Yu's user avatar
1 vote
0 answers
48 views

Is there a way to test if a code don't have any issues without actually running it?

I have a code that is too much for my computer to hold. This code will be computed later in a powerful system. Is there a way to verify if there is some syntax error or another issue with the code ...
Filburt's user avatar
  • 578
1 vote
0 answers
92 views

Numerical integration graph and convergence

I am trying to do the following integral numerically, My question is that, after the integration, when I tried to plot, the plot does not show anything on it. What did I do wrong? Furthermore, I ...
Duke Smith's user avatar
1 vote
0 answers
142 views

Fourier Transform(first use)

This is in continuation of the question I asked Wrong evaluation of integral in Mathematica? But I will try to make it self contained. I have a periodic function ...
L.K.'s user avatar
  • 683
1 vote
0 answers
82 views

Funny behavior when integrating

Having the defined the following: ...
Mirko Aveta's user avatar
  • 2,202
1 vote
0 answers
201 views

A faster way to make a loop that takes as input previous iteration values

As mention in other answers, I know that there are faster ways to construct loop in Mathematica, using Fold or ListTable. In my ...
statguy789's user avatar
1 vote
0 answers
112 views

Optimizing my code for Mathematica Online

I defined this function: s[n_] := Block[{m = 1}, While[Mod[++m!, n] != 0]; m] I would use ParallelTable on my laptop, but it ...
Chen Stats Yu's user avatar
1 vote
0 answers
209 views

How to eliminate all terms of a variable with square root in an equation?

I did the following thing: take an equation with square root terms, by moving terms and squaring two sides, finally ending up with a polynomial of the specific variable. My algorithm is like this: ...
vapor's user avatar
  • 7,921
1 vote
0 answers
337 views

Collision detection algorithm (discrete) with sweep and prune algorithm for periodic boundary conditions

EDIT: Question Updated with solution approach, but solution much slower than original implementation. Any ideas to speed up implementation? In the discussion on collision detection (see here) I asked ...
Rainer's user avatar
  • 2,931
1 vote
0 answers
115 views

How to Fold (FoldList) this in a more compact (efficient) way?

Example code: x = Table[something[i], {i, 5}] Table[Fold[f1[#1, f2[#2, a], a] &, x[[i]], {c1, c2, c3}], {i, Length[x]}] This above is just an example. I ...
Chen Stats Yu's user avatar
1 vote
0 answers
94 views

Some problems with complied function

...
Chen Stats Yu's user avatar
1 vote
0 answers
203 views

Am I simulating correctly my hidden markov chain?

I want to simulate a hidden markov model, in which $y_t|y_{t-1},x_t=i \sim N(\theta_0y_{t-1}+\theta_i,\sigma^2)$, where $y_t$ is the observations or data, and $x_t$ is the state variable of the ...
An old man in the sea.'s user avatar
1 vote
0 answers
88 views

Problem with converting recursive code to iterative

I am trying to convert a snippet that uses recursion into one that uses iteration for drawing an L-tree, but my code produces duplicate points. How do I avoid generating them? Recursive version: <...
matrix42's user avatar
  • 7,138
1 vote
0 answers
82 views

Implementing normalization/rescalement from a Tutorial

I'm trying to implement a rescale/normalization as is described in here by mathematical expressions in page 10, and code in the top part of page 16. The notebook is also available here. The objective ...
An old man in the sea.'s user avatar
1 vote
0 answers
152 views

How to tweak the following purely numerical code

I am using the following numerical function in my program and I would like to speed it up. ...
ftiaronsem's user avatar
0 votes
0 answers
37 views

Using NetMeasurements for basic neural network

I have a neural network that works fine, but I would like to obtain some results on the Validation Set which provides some metrics on the performance of the training. I am obtaining some strange ...
John Doe's user avatar
  • 271