Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

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
115 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
49 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
55 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
61 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
140 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
72 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
59 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
152 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
96 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
56 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}; ...
1
vote
0answers
78 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
53 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
5
votes
3answers
105 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
435 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
403 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: ...
15
votes
6answers
802 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
52 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
287 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
153 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
88 views

Can a certain pair of expressions be compressed into one?

I've been employing this pair of statements ...
1
vote
1answer
56 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 ...
0
votes
1answer
76 views

Finding the limit of a function

I have the following code: ...
1
vote
3answers
109 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
70 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
114 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
175 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
129 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
93 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
198 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
91 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
84 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
90 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
48 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} (...
1
vote
0answers
37 views
0
votes
1answer
51 views

Creating a numerical sequence with Do [closed]

I have the following code: n = 10 nt = 2 ns = nt * n inte = Range[n - 1] Do[i = inte/n, {i, nt}] I am trying to create a list that has the following result: 1/...
6
votes
2answers
101 views

Efficient way to partition list of expressions based on its contents

I have a list of polynomials polys linear in a set of variables vars. How do I partition the list based on successive dependence ...
1
vote
1answer
90 views

Writing function restrictions more efficiently

I define the two functions: ...
3
votes
1answer
78 views

Generating numbers palindromic in two number bases

The purpose of the code below is to generate numbers that are $2d+1$ digit palindromes in number base $b+1$, and are also palindromic in number base $b+3$, where: The ...
4
votes
0answers
284 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 ...
6
votes
2answers
122 views

Checkboxes to ranked list

So, my aim is to produce a user interface with checkboxes not only returning True/False, but also the order in which they were ...
3
votes
1answer
75 views

Poor performance from Manipulate and Sow-Reap

I am not a mathematician, and I barely know how to use Mathematica. But, over the course of many months and with help from this site awhile back, I managed to generate dynamic output that does exactly ...