# 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.

304 questions
Filter by
Sorted by
Tagged with
148 views

### Modifying codes in a more 'Mathematica' way

I have the following codes: ...
2k views

### Is there a more elegant way to write this statement?

Total[TakeWhile[Map[#^3 &, Range[1, 200]], # < 10000 &]]
413 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, ...
153 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: ...
609 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 ...
107 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 ...
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: ...
136 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 ...
428 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 ...
214 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? ...
821 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 ...
136 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 ...
958 views

### Enneper's minimal surface

How to plot the Enneper's minimal surface like this I tried: ...
1k 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 ...
97 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: ...
348 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 ...
39 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: ...
239 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 ...
241 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 ...
103 views

### Partial comparison between lists contained in larger matrices [closed]

Please presume we have two nested matrices m1 and m2: ...
329 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 <...
130 views

### sorting eigenvectors of a final combined matrix

I have two matrices m1 and m2 as below: ...
374 views

### Tips to write more readable code [closed]

What are some tips to write a more readable code? For example in C, tab is your friend. You can also declare variables in a way such that you can read the code easily later on. In Mathematica, if ...
169 views

### Maxima turn out to be false maxima when extremising function locally

In short: I have a 2-D function that gives this plot, where the orange dots are maxima: There are 4 maxima in this plot. Now, I plot the function again in a smaller region, close to these maxima, ...
188 views

### Solving problem using recursive functions

Attached below is a question posed by the Canadian Mathematical Society, and I have my code and answer. Is there a better way of writing the code, and will the answer be different as a result? My ...
158 views

### Understanding simple code [closed]

Can anyone help me with how to understand the definition of the ExpandNCM function listed in the NonCommutativeMultiply ...
275 views

### The equivalent of dplyr mutate with Dataset

In R, there is a package "dplyr" that works on data.frame objects, which is one of the origins of the Mathematica Dataset construct. One of the things dplyr can do is "mutate" the columns of a data....
3k views

### converting Matlab program to Mathematica code

I have the following Matlab program; ...
204 views

### Plot of The RiemannSiegelZ Function

I would appreciate your help to visualize the of the following function RiemannSiegelZ[x] with this range. { 18154980120849865 , 18154980120849885 } I tried this: ...
601 views

### Eigenvalues and Eigenvectors Order [duplicate]

Say I have a list of eigenvalues and eigenvectors produced from a matrix $M$ using the command {eig1,eig2}=Eigensystem[M], which will return the eigenvalues with ...
48 views

### Variable Definitions and Random Numbers [closed]

I have currently created the following matrix: m={{RandomReal[{0,1}],RandomReal[{0,1}]},{RandomReal[{0,1}],RandomReal[{0,1}]}} In other words, a $2 \times 2$ ...
97 views

### Saving Dot-ed eigenvectors in a special comparison [closed]

We have produced a 4*4 matrix in any iteration containing nx from 0 to 2 by steps of 0.5. and in any iteration we have saved sorted orthogonalized-eigenvectors based on their eigenvalues with this ...
109 views

### How to define UpValues of NBSpline when the length of argument is unknown?

I mimic the built-in BSplineBasis[] to build a user-defined function NBSpline[], Namely, ...
136 views

### Memory Management for Large Datasets [closed]

I've written some Mathematica code to generate polynomial roots. The code take an argument n as the highest degree of polynomial to solve for and then exports a file containing a list of the roots: <...
104 views

### Sort and Save Matrices Eigenvectors to a Larger Matrix

We are going to sort and save all orthoginalized-eigenvectors of 4*4 random matrices (produced in any iteration) to a larger matrix such as storagematrix. Since, produced random matrices are 4*4, ...
97 views

### Reducing quantile & color map queries for use with Associations [closed]

This set of queries perform basic maps to quantile and then color-map. There's got to be a more compact solution. What are some approaches to reduction? Numeric: ...
127 views

### Composition vs serial assignment, which performs better?

I have a giant block of code that manipulations an expression in many different ways. Currently it looks like ...
613 views

### Having trouble translating Matlab fsolve into Mathematica

I searched the site and found that someone said FindRoot is equivalent to fsolve, however, without proper options, ...
167 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. <...
66 views

### extraction new generated vectors in module with replaced parts

We have four vectors: ...
532 views

### Forecasting problem with Geometric Brownian Motion in Wolfram Mathematica [closed]

I'm a full time undergraduate student from Peru, and I'm trying to use the Geometric Brownian Motion example used in the help section from Wolfram Mathematica in order to forecast future stock prices,...
190 views

53 views

### How to get the dynamic expression

$$Z_{n+1}=\frac{\alpha Z_n}{1+Z_{n-1}}$$ How to write the above expression in Mathematica? I want to get say Z_100, Z_10 by that scheme. Can I call say $Z_{10}$ if $Z_{n+1}$ is given?
199 views

### How can I do a two dimensional Fold? [closed]

I'd like to Fold over higher dimensional objects than lists. Semantically, the format would be something like ...
172 views

### How to find total distance covered when I have a list of GeoPositions?

So I have a list of GeoPositions and I need to find the distance covered in that order? I know I can find the distance from each city and then add them all up but I was wondering if there is any ...
144 views

### usage of random numbers in recursive loop

I am trying to evalute two functions using iterative process as below ...
I am generally confused about integer valued polynomials, and how to count them. Trying to learn the subject I started by listing permutations of the rows in a lower triangular table: \displaystyle ...