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.

Filter by
Sorted by
Tagged with
3
votes
2answers
74 views

Extract outputs from a WHILE loop in a table format

How can I convert my multiple outputs of a while loop in a table form and save it for later use. Here is a sample code: ...
1
vote
1answer
67 views

Improve code style

I want to calculate r, theta and phi. My code is very ugly. How would you propose to obtain the same results? ...
0
votes
0answers
50 views

What techniques have you employed to avoid loop in Mathematica? [duplicate]

It appears to me that loop in mathematica is very slow (compared with matlab). Since many people still use mathematica to finish their work, there must be some techniques to bypass this problem. ...
4
votes
2answers
102 views

How to make my code to generate polytopes more efficient?

The main purpose of my code is to generate polytopes by starting with a point. With this point, I then apply 3 actions which generates at most 3 others points: ...
6
votes
8answers
2k views

Simplify the code

I have a function that grabs the second part of the list and change it to times, ...
0
votes
0answers
45 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. ...
13
votes
3answers
627 views

Concise way to draw this pyramid

I wrote the following to draw a pyramid, this approach uses functions TranslationTransform and Tuples, is there a way to do the ...
2
votes
1answer
123 views

Monte Carlo Simulation of a Double Well Potential (Edited)

I am looking for a possible way to simulate the temperature effect on a collection of atoms sitting within a double well potential, say something like ...
2
votes
1answer
37 views

User Implemented SHA-1 is failing for strings of length >512 bits

So, earlier, I posed a question regarding getting a user implemented SHA-1 hash function to work correctly. Well, I fixed the problems, cleaned it up a little bit, but now I have the problem for when ...
3
votes
1answer
121 views

User implemented SHA-1 isn't outputting correct hash

EDIT: I'm actually Thinking the issue is in the initialization phase, where we pad the message with 1's, 0's, and the message ...
3
votes
2answers
1k views

The most efficient algorithm to find all possible integer pairs which sum to a given integer

I wrote a module in Mathematica which finds all possible pairs of integers from a specified list of integers (which can be negative, zero, or positive) which sum to a specified integer m. The only ...
2
votes
1answer
53 views

Cell formatting and hiding code

I've written some code that's been getting longer and longer, Is there a way to "hide" the section of the code that does not require input so that i can just give it my two inputs and jump straight to ...
1
vote
0answers
64 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
1answer
66 views

Mathematica only graphs the upper part of my cylinder

I have this code which first is supposed to make random points, draw lines through the points and then make these lines radical axes of cylinders. I have two problems with my code. First, it only ...
5
votes
1answer
147 views

Can someone please explain the code from another question

Source: Position of a pattern-matched part of an expression Can someone please explain the following code by Leonid Shifrin. ...
3
votes
2answers
75 views

Dealing with stiffness in solving Mukhanov-Sasaki equation

The code that I wrote is rather long, but I have included the whole code. ...
0
votes
1answer
60 views

I have a working code, but work very slowly. want to improve the code

I have working code which gives the result as expected by me. But the problem is it is taking too much of time to give me those results. I have a determinant function which depends on z1,z2,z3, kt,m, ...
0
votes
0answers
23 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 ...
3
votes
2answers
157 views

Animated Lissajous Curves Parametric Plot

I love mathematical GIFs' power to illustrate and communicate math concepts widely. I haven't had much luck with the build-in ListAnimate on MMA Online but ...
0
votes
2answers
128 views

When computation takes a long time, how to find out if this is normal or if my script contains an error?

I study mechanical engineering and I' working on my first bigger project on Mathematica right now. It's a multibody problem that leads to a system of 4 large equations I'm supposed to solve ...
1
vote
1answer
61 views

Find and number sublists

I implemented the following routine. array1 = {12, -12, 14, 12, 1, -3, 1, 1, 2, 7, 8, 102, 2, 3, 3, 1, 332, 11, 23, 2, -2, 13, 12, 1, 1, 1, 1, 1, 1, -121, 131}; ...
0
votes
0answers
81 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
1answer
64 views

Trying to obtain a numeric solution to an inequality. Code might be not working as intended

I need to check whether an inequality can have solutions in the real numbers, given some extra constraints on the variables. I suspect that no solutions exist but I would like some verification of ...
0
votes
1answer
56 views

How to remove the 2 same plot from arrays of plot

...
5
votes
3answers
110 views

Better code for reversing and joining matrices

I am writing a function to reverse a matrix and join the reversed version to the original one, making a new matrix which I call A. And after doing this, I reverse <...
8
votes
1answer
450 views

Is there a faster way to vectorize a matrix than this?

I want to put all the columns stacked up, as a vector. The fastest code I could come up with was Transpose[{Flatten[Transpose[A]]}] Is there a faster way?
6
votes
2answers
407 views

Computing the twin prime constant with Mathematica

The twin prime constant is defined as $$ C _2 = { \prod \limits_{p \geqslant 3 }} \, \frac{p(p-2)}{(p-1)^2}. $$ Translating this directly in Mathematica code gives: ...
1
vote
0answers
76 views
15
votes
6answers
804 views

Better way to sort course grades

I use the following code to create a histogram of grades. Grades are provided as a List of strings such as "A-", "D+", "E" (don't ask), etc. The +/- substitution hack is necessary to sort the grades ...
3
votes
1answer
54 views

What is a good way to implement a versatile folder structure checking system?

I'm writing an 'application' (set of *.wl and *.wls files) that requires a given folder structure to function; I am not sure how this structure will eventually look like, because it changes as I ...
6
votes
1answer
298 views

What is wrong with this code? (Usage of FunctionInterpolation and how to make code efficient)

I am trying to create an interpolation out of a function that comes from an improper integral. The end goal is to make a 3d plot over a specific region. Specifically, I have the following code: ...
5
votes
3answers
160 views

Improving the run time of random walk simulation

One of our professors told us that during his thesis he used Mathematica in simulating it since it is about networks, I don't know how he did it but all I know is he said it took about two weeks to ...
5
votes
1answer
91 views

Can a certain pair of expressions be compressed into one?

I've been employing this pair of statements ...
1
vote
1answer
58 views

Is this decryption function idiomatic?

This is my first non-trivial Mathematica notebook, which I wrote for a cryptology homework. It encrypts/decrypts strings using an affine cipher. Is the code readable/idiomatic? How could it be ...
1
vote
1answer
70 views
0
votes
1answer
76 views

Finding the limit of a function

I have the following code: ...
1
vote
3answers
112 views

Is there any better way to generate random unique quadratic equations with rational zeros, simplest integer coefficients?

This is my attempt but I want to make it more compact if possible. ...
2
votes
1answer
71 views

How to use `Pattern` and `Slot` to match n-element conditions?

Extract the qualifying sublists. – Condition: The elements are all in the Reals and greater than zero. Question If the sublist contains many elements, how can it ...
1
vote
2answers
116 views

How can I make this code simpler, readable and more efficient?

I am running an iterative routine that I want to export to a file while each iteration is computed, instead of storing everything in memory and then exporting to a file. My solution is to write to ...
1
vote
0answers
50 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 ...
3
votes
1answer
193 views

Exporting a Manipulate expression to .avi and .gif

I've the following code: ...
1
vote
1answer
62 views

Using two functions to plot one function

I want to plot the following function, where Uin is the variable (that has to be on the x-axis): ...
1
vote
1answer
134 views

Convert MATLAB Code to Mathematica

I have written a MATLAB code as following, in order to calculate an integration involving Modified Bessel Function with variable limits: ...
5
votes
1answer
94 views

The reason behind ControlToBoxes (DynamicDump`)

Background I'm trying to establish best practices for custom controllers programming. This question is about one top level aspect of it. WRI suggested (few talks I don't remember right now) to ...
1
vote
1answer
209 views

Making a slow code with symbolic manipulations faster

I have a code with symbolic manipulations. It works fine but very slow (e.g. for w=14 it's reasonably fast but I want it to work for ...
0
votes
1answer
95 views

an answer for my yesterday question about determinant of matrix

Yesterday and about five months ago, I asked two similar questions but nobody could answer me; maybe because my question was ambiguous. But, I myself tried and I could finally find my desired answer. ...
2
votes
1answer
85 views

How to program MapList? [closed]

I would like to know if there is a nice functional way to code up a MapList which applies f to each element of ...
1
vote
0answers
100 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 ...
0
votes
0answers
49 views

Why does my code find minima outside the square that constrains my search?

I have written a script to find the minima of a function, and then manipulate them. I have a physical expectation on what the result should look like, but I am not seeing this and I am wondering ...
0
votes
1answer
54 views

Plotting a dynamical system code fix needed! [closed]

So I'm trying to plot a system of differential equations separately and look at how their solutions behave: $$\dot{x}_{1} = x_{1} (K_{1} - x_{1}) + \epsilon (x_{2} - x_{1})$$ $$\dot{x}_{2} = x_{2} (...