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.

learn more… | top users | synonyms

2
votes
3answers
132 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
0answers
17 views

Making PersistentObject more seamless

When reading the changelog for Mathematica 11.1, I immediately got excited about PersistentValue, since it seems useful in a lot of cases. However, I was a bit ...
1
vote
1answer
54 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: ...
1
vote
0answers
33 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
62 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
32 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 ...
0
votes
0answers
43 views

Newton method on truncated normal distribution

g[] and G[] are the desnity and cumulative distribution function. Then I define the function, which I want to minimze which is j[e,f,n,a]. I would like to know where the minimum e(f) in dependence of ...
1
vote
3answers
70 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)$. ...
3
votes
0answers
70 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
131 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
79 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
110 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
70 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
132 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
181 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
119 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
71 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))^{-\...
6
votes
1answer
199 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 ...
10
votes
1answer
281 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
72 views

Funny behavior when integrating

Having the defined the following: ...
2
votes
0answers
215 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
182 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
83 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
117 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
78 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
89 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 ...
7
votes
2answers
141 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
53 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
62 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): ...
0
votes
2answers
137 views
8
votes
7answers
2k views

Is there a more elegant way to write this statement?

Total[TakeWhile[Map[#^3 &, Range[1, 200]], # < 10000 &]]
6
votes
2answers
175 views

Sound synthesizer using Manipulate

Sound synthesizers, both digital and analog, often include a parameter section for shaping the amplitude of a sound wave over time. This parameter section is commonly known as an "ADSR EG" (attack, ...
0
votes
1answer
65 views

Mean brightness and the standard deviation of columns in a gray scale image

I want to calculate the mean brightness and the standard deviation of columns in a gray scale image (8bit). Can the following calculation code be made faster or/and shorter: ...
0
votes
1answer
163 views

Making a bouncing ball simulation interactive [closed]

Problem A ball initially at height $h_0$ above a horizontal surface is dropped at time $t = 0$ with zero initial velocity. When it arrives at the surface, the ball bounces in the vertical direction ...
1
vote
1answer
82 views

Efficient method to calculate green's function between points

I am working on an analytical model for sound radiation from a cylinder. As part of this work I am using the boundary element method to predict the sound pressure at a particular location away from a ...
16
votes
8answers
2k views

How to avoid procedural loops in this example?

I want to iterate over a list, and return the index as long as I found the first element satisfying my condition. Written in a for loop: ...
3
votes
1answer
73 views

How to index multi-dimensional vectors in NDSolve/WhenEvent?

I want to solve a system of coupled ODEs using NDSolve with WhenEvent. But I'm having a hard time trying to index the state ...
2
votes
2answers
226 views

Multiple object detection and tracking in images

The code below: reads in a number of png images, where the background is dark and objects of interest (here 3) are bright dots determines in each image the coordinates and other information ...
1
vote
2answers
105 views

Using solve on conditional functions

I know that the code is pretty long, but most of it is just defintion. Do you see why the Solve gives me "his system cannot be solved with the methods available to Solve" back? ...
12
votes
3answers
384 views

How to check the validity of an option value

I have a user-defined function, func, which takes the following form: func[arg1, arg2, options] Here is the actual code ...
4
votes
1answer
128 views

What is wrong with my code so it neither produces a correct plot nor an error message?

I am trying to define some initial functions and then using them to define my secondary functions and then plot the secondary functions. I am supposed to get two curves with a finite width ...
1
vote
3answers
399 views

Enneper's minimal surface

How to plot the Enneper's minimal surface like this I tried: ...
10
votes
1answer
342 views

How to construct the RHS of Wick's theorem

I've been trying this for a few days now, but I just can't seem to find an efficient (speed-wise) functional way to code the following task. Context: I would like to construct an expressions that is ...
0
votes
1answer
52 views

Exporting in .dat format [closed]

I am new to Mathematica. I am trying to write the data of the plot of some function which I am using in a .dat format. I am using the following commands to do so: ...
0
votes
1answer
134 views

NDSolve for a system of nonlinear coupled pde

I try to solve a system($n$) of coupled nonlinear 1-d PDE's which is basically coupled sine-Gordon equations (through 2nd spatial derivative) in time and space. I am interested in the dynamics when I ...
2
votes
1answer
38 views

wrong result of an iteration related to replacement and comparing

We have two nested matrix and a code for replacement following an equality as: ...
1
vote
3answers
208 views

How to combine Tabview with Dynamic Graphic to change the colour of a polygon

How does one get TabView to specify the colour of the Polygon? How does one put a label on ...
1
vote
1answer
71 views

FilterOptions Errors with Riemann Sum Notebook on Math World

I am trying to run the notebook for a maximum (upper) integration calculation (hopefully, symbolically). I am using the notebook available at Wolfram Math World (upper left of web page). When I ...
1
vote
2answers
94 views

Partial comparison between lists contained in larger matrices [closed]

Please presume we have two nested matrices m1 and m2: ...
1
vote
1answer
215 views

How to write this Matlab code in Mathematica

I have a small hiccup here. I am trying to write my Matlab code for a dynamical system in Mathematica. I have managed to get most of it except one part. The Mathematica code for the system is <...