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
2
votes
0answers
40 views

How can I fix this cycle in order to iterate several times? [closed]

I have been working on a code whose only purpose is to get the mean value over four numbers. And I managed to do one cycle, however after trying to repeat this process until a certain condition is ...
1
vote
2answers
91 views

Force an Im-Re separation in a complex number with parameter

I was doing a computation with Mathematica (summing a series) and a part of the result was the following: $$\frac{\Gamma \left(\frac{1}{4}\right)}{3 \sqrt{2} \sqrt[4]{-\frac{\sqrt[3]{r^3}}{2}-\frac{1}...
2
votes
1answer
73 views

How generalizes (automate) recursive code

This is a small version of my code (for n=2): ...
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 ...
4
votes
0answers
268 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. ...
1
vote
1answer
92 views

Using AxesOrigin in LogLogPlot

This is my problem: this is the code I have to plot ...
12
votes
4answers
755 views

Reduce Code Length

I have the following that works good, and computes in one shot,but the code is so long. Can someone please help me to reduce the size of this? ...
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 ...
0
votes
1answer
519 views

Translate image-processing Matlab code into Mathematica

I need some tips how to translate this Matlab code into Mathematica code. ...
1
vote
2answers
59 views

What is the alternative to Factor and Distribute?

Below is my toyproblem code I am trying to improve. ...
3
votes
2answers
414 views

Problems with PlotRange

I have the following function: $$f(x) = \frac{2\arctan(\sqrt{\omega^2 + 1} - \omega)}{1 + \frac{1}{2}\ln(1 + \omega^2) - \ln\omega}$$ And something strange happens when I am going to plot it with ...
3
votes
3answers
171 views

Speeding the search for amicable numbers

The following text is from Problem 21 - Project Euler : Let $d(n)$ be defined as the sum of proper divisors of $n$ (numbers less than n which divide evenly into $n$). If $d(a) = b$ and $d(b) = a$,...
5
votes
0answers
76 views

Helping Mandy become a better speller [duplicate]

tl;dr Can you improve upon this code, which checks to see if a word can be spelled using the element symbols from the periodic table? I recently created a periodic table that lights up. The design ...
5
votes
5answers
485 views

Rotating squares

I have here an example of how a rotation matrix operates a parametric representation of a square. ...
3
votes
1answer
77 views

Demonstration site CDF error correction question

I use Mathematica ver11. However, the following error is displayed when running Demonstration site. http://demonstrations.wolfram.com/ThreeOrthogonalProjectionsOfPolyhedra/ ...
5
votes
2answers
112 views

Optimizing user defined graphicQ, test of graphicness of a sequence

A sequence of non-negative integers is graphic if it is the degree sequence of some simple graph. Graph realization problem is the decision problem where it is asked whether a given sequence is ...
1
vote
2answers
57 views

Plot issue and numerical disagreement

I have to plot this function: Q[ω_] := ArcTan[1/ω]/(1 + 1/2*Log[(1 + ω^2)/ω^2]) And I did it through ...
0
votes
1answer
81 views

Mathematica and its use of Conditions, Assumptions and so on

I don't understand why Mathematica has to be such a pain in the ***. ComplexExpand[(I*ω)^(-3/4), TargetFunctions->{Re, Im}] The result is $$\frac{\cos \left(\...
0
votes
1answer
705 views

Heun's method for a system of ODE's [closed]

I need to solve a system of two ODE's using improved Euler's (Heun) method. Can any one help as I am pretty bad at Mathematica. This is what I've come up with so far ...
0
votes
1answer
103 views

Maximimize not working properly?

I try to evaluate the Integer Maximum of a given function under constraints. ...
0
votes
0answers
71 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. ...
9
votes
2answers
658 views

Optimizing Mathematica Code

I have implemented the whole Baum-Welch Algorithm for training Hidden Markov Models as described in Rabiner's paper Here is my code that calculates the Forward Probabilities` ...
5
votes
2answers
145 views

Better way than using multiple flattens?

I am running some calculations with vectors (lists) and in order to perform them, they need to be flattened. Is there a better or neater way to do this? ...
2
votes
3answers
185 views

How to find all prime power factorizations of an integer

I want to put in $n$ and get the possible factorizations into prime powers. Let's say for 24 I want {{8,3}, {4,2,3}, {2,2,2,3}}. The algorithm for doing this on ...
0
votes
1answer
82 views

How to create list

I have a law under which the current changes, and i need to find values of current evry f sec. Code is: ...
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
385 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 ...
0
votes
1answer
39 views

Help in performing computation over a list [closed]

I need to compute the quotient $\frac{n-1}{\sigma(n)-n}$ over the list say $\{9,25,49,81,121,169,...\}$ where $\sigma(.)$ is the classic sum of divisor function. I tried to use the following codes ...
1
vote
3answers
177 views

A modification of a mathematica code that selects perfect square on the list

Below is a code taken from OEIS that generates integers $n$ such that $\sigma(n)-n\mid (n-1)$. ...
6
votes
1answer
897 views

Two-Point correlation function of Ising data is not giving expected results

Due to the nature of my problem, and readers perhaps not having a physics background, I need to give some context to my problem which is intrinsic to it. The problem however is not a physics one, but ...
2
votes
1answer
154 views

Speeding and optimizing the Graphics Plot

I am having a Hermitian Matrix(HCF[k]) depending on a parameter $k$. My job is to plot the Eigenvalues of the matrix as the parameter $k$ is changed. But 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 ...
2
votes
1answer
141 views

Wrong evaluation of integral in Mathematica? Numerical vs symbolic [closed]

I have Mathematica 11.0.1 in Ubuntu 16.04. My problem is that I have an integral but Mathematica is evaluating it wrong. Here is the integral: ...
0
votes
2answers
151 views

Find Root condition for polynomial

I have the following 12-th order polynomial in $\lambda$ with a parameter dependency in $u$: ...
1
vote
1answer
258 views

Wolfram|Cloud memory limit exceeded

I have some formulas from a paper (Provably Manipulation-Resistant Reputation Systems) that I would like to run 3 times (with different nummbers). Therefore, I wrote a small programm that now finally ...
0
votes
1answer
231 views

Population growth model using cohort data method: Is there a way to make the repetitive code simpler?

This is for a little simple project in which we try to model population of a certain species of fish and the impacts of overfishing I do find it rather rudimentary to write it all out as such and was ...
1
vote
1answer
230 views

FEM - How to use an If rule for different ElementMarker values within NDSolve

This question is partly based off Gonza's question and Mauricio's answer. I wanted to adapt the FEM method to simulate a point pressure being applied to distort an encapsulated material that is ...
1
vote
1answer
128 views

Problem with my Simpson method for elliptic integral [closed]

Using code I found from here for adaptive Simpson's method, Numerical Integration Via Adaptive Simpson's Method, I tried to implement it into my own equation, $(1 - (\sin^2[51/2])(\sin^2 x))^{-\...
7
votes
1answer
290 views

The curious case of missing random-walking particles in the box

Note: I added the entire code I wrote below to generate the initial configuration and have explained step by step what each part of the code does Kindly bear with the code and the explanation. Since ...
12
votes
1answer
947 views

Problems with stress distribution using FEM

I'm trying to get the displacements u(x,y) and v(x,y) of a beam simply suported, the stress distribution in the middle section should be a linear function: but i'm getting this: My code is: ...
1
vote
0answers
80 views

Funny behavior when integrating

Having the defined the following: ...
3
votes
0answers
707 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
2answers
1k views

Numerical Integration Via Adaptive Simpson's Method

I have written a code that uses the Adaptive Simpson's method to approximate integration. For those who are unaware of this Adaptive Simpson's method; Adaptive Simpson's method In my code, I count ...
2
votes
1answer
286 views

Flip the axes in the Histogram Plot

I have a matrix and I would like to plot the square of its element. n = 10; H = RandomReal[{0, 1}, {n, n}];; MatrixForm@H H1=H*H; Histogram[H1[[1]]] First row is ...
2
votes
2answers
158 views

Nearest numbers in the list

I am just curious that there is any better way to write the code to search the nearest value than what I wrote below ...
0
votes
2answers
138 views

How to multiply simultaneously more than one rows with each other [closed]

I want to simultaneously multiply more than one rows with each other. Like 1 with 2 and 3 with 4 likewise. ...
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 ...
8
votes
2answers
173 views

How to implement this simple procedural style algorithm efficiently in Mathematica style code?

I am trying to move my C solution code for project euler problem 135 to Mathematica. But I encountered serious performance problem. The algorithm is very simple, here is a plain translation: ...
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 ...
3
votes
1answer
92 views

Controlling the motion of points in an animation

I am looking for a better way to show this behavior on a pressure-composition diagram for immiscible liquids (two black dots show behavior at different x-positions, only one is present otherwise): ...

1 2
3
4 5
7