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
41
votes
0answers
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 ...
5
votes
0answers
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, ...
4
votes
0answers
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 ...
4
votes
0answers
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. ...
4
votes
0answers
294 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}+\...
3
votes
0answers
706 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 ...
3
votes
0answers
511 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)...
2
votes
0answers
73 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 ...
2
votes
0answers
381 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 ...
1
vote
0answers
110 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}\...
1
vote
0answers
77 views

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

...
1
vote
0answers
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 ...
1
vote
0answers
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 ...
1
vote
0answers
40 views

understanding en fixing the error in DSolve system

Why does this code not work: ...
1
vote
0answers
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 ...
1
vote
0answers
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 ...
1
vote
0answers
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 ...
1
vote
0answers
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 ...
1
vote
0answers
80 views

Funny behavior when integrating

Having the defined the following: ...
1
vote
0answers
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 ...
1
vote
0answers
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 ...
1
vote
0answers
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: ...
1
vote
0answers
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 ...
1
vote
0answers
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 ...
1
vote
0answers
84 views

Some problems with complied function

...
1
vote
0answers
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 ...
1
vote
0answers
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: <...
1
vote
0answers
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 ...
1
vote
0answers
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. ...
0
votes
0answers
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 ...
0
votes
0answers
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 ...
0
votes
0answers
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 ...
0
votes
0answers
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. ...
0
votes
0answers
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 ...
0
votes
0answers
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,...
0
votes
0answers
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 ...
0
votes
0answers
83 views

Problem with a numeric 1/0 in NDSolveValue

The following code tries to solve three coupled differential equations with some fixed parameters ...
0
votes
0answers
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 ...
0
votes
0answers
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. ...
0
votes
0answers
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. <...
0
votes
0answers
96 views

Matrix iteration failing after second step

I am calculating 11x6 matrix using different logics as in below code. Problem is in Do loop in below code where I have two different criteria to update matrix "fd". I am expecting logic in IF which ...
0
votes
0answers
68 views

NDSolve accepts no multiplier in argument

...