# 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.

42 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2k 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 ...
100 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, ...
436 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 ...
267 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. ...
294 views

77 views

...
61 views

### Get Ticks both in Frame as in Axes

Why have the numbers disappeared from in the $X$ Axis ? Is there some way to keep the Frame and having the numbers on the ...
125 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 ...
40 views

### understanding en fixing the error in DSolve system

Why does this code not work: ...
59 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 ...
37 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 ...
88 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 ...
135 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 ...
80 views

### Funny behavior when integrating

Having the defined the following: ...
157 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 ...
88 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 ...
188 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: ...
274 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 ...
102 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 ...
84 views

...
188 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 ...
82 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: <...
75 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 ...
151 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. ...
26 views

### Improvement of a method to plot values of a section of a line that moves with time

I have this code which animates a layer of fluid moving on the outside of an ellipse with a moving black point on the cylinder surface itself. I want to plot a line from the origin to the outer layer ...
53 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 ...
38 views

### NIntegrate convergence problem

I have an integral that does not converge satisfactorily for some values and appears random. I have included the code (and plot). However, since the integral depends of imported data, it cannot be ...
61 views

### Fourier Transform and Inverse Fourier Transform of Lists

I am trying to compute the Fourier transform of a list, say an array of the form {{t1, y[t1]},.....{tn, y[tn]}}; apply some filters in the spectral components, and then back transform in time domain. ...
26 views

### Relative Chop for Fractions with Trigonometric Terms

I have a fraction, which contains long sums of various terms that might include trigonometric functions in both the numerator and denominator. I want to get rid of the negligible terms. This is my ...
103 views

### How can I make my code containing a For loop more Mathematica-style?

I know there are a lot of questions on this site regarding the use of For loops and how to avoid them in Mathematica. However, in my case I believe it is justified,...
58 views

### Select from list: has elements from another list

Consider a data list data, and a rule list rule. I want to select from data all elements ...
83 views

### Problem with a numeric 1/0 in NDSolveValue

The following code tries to solve three coupled differential equations with some fixed parameters ...
40 views

### Eigenvectors calculation doesn't match from two identical results

I have a $3\times 3$ matrix, depending on a single parameter. My job is to find the eigenvectors for the matrix. I tried two ways, shown below ...
70 views

### (Naive) Manual implementation of DFT results in long sum which is very inefficient to plot, can my approach be saved?

I will do my best to keep this question as short as possible, I am afraid though that I wont be able to get my issue across if I don't elaborate on the background and provide my code as an example. ...
166 views

### Inverse Superposition

There are 4 tables that, I have written them as bellow: (m, n, s, and r are orthogonal basis. r.r=n.n=m.m=s.s=1, and m.n=n.r=...=0). a's, b's, c's and d's are coefficients and are numeric values. <...