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
1 vote
1 answer
68 views

How to use an "otherwise" clause in `Which`

I want to classify a set of vectors according to the number and position of zeroes they contain. The components of the vectors are non-negative. I'm using ...
user avatar
  • 541
0 votes
0 answers
61 views

How do we define the function near the end of my post?

Suppose I have two sets $F_{1,n}$ and $F_{2,n}$ written as: ...
user avatar
  • 199
5 votes
4 answers
398 views

Is there a more elegant solution than f[a, b, Sequence@@#3,...]?

I am trying to construct a list of many possible combinations using Outer and Permutations. Something that looks like that: <...
user avatar
1 vote
0 answers
45 views

How to rescale list to interval $(0,1)$ [closed]

Imagine I have an arbitrary list l = RandomReal[{-5, 10}, 10] Out[]= {4.17452, 1.75762, 4.16905, -3.63225, 8.34172, 5.39626, -4.2107, 3.50873, -1.52441, -3.7147} ...
user avatar
  • 4,138
0 votes
1 answer
88 views

when I run the notebook, without any results, where is my mistakes?please help [closed]

...
user avatar
  • 1
0 votes
0 answers
55 views

Code Producing FindMinimum::nrnum; how do we fix it?

Suppose $A=\left\{\sqrt{m}:m\in\mathbb{N}\right\}$ and $S\subseteq A$: I wish to create a code which finds: $$\min\left\{c:\forall(d\in S)\exists(c\in A)\left(c/d\in A\right),\max(S)\le c \le \prod\...
user avatar
  • 199
1 vote
1 answer
43 views

Check certain expression using a while loop to run through all posibilities in a range

Well, I have written the following code (using the fast square root test found in this answer): ...
user avatar
  • 1,723
1 vote
1 answer
46 views

How to number each element of a list to form a table of points? [closed]

Suppose we have a list given below OurList={a,b,c,d,e} Is there a way to attribute a number to each element of OurList so that we could form a table of points? The ...
user avatar
  • 43
0 votes
0 answers
19 views

Table of time-varing calculation slower to the point of kernel blowing up

There is a complicated function obtained by numerically solving a pde, let us call it $u(t,x,z)$. For this $u$, I want to calculate the global maximum of $u^2$ at a fixed position of $z$, and plot ...
user avatar
  • 43
0 votes
0 answers
18 views

How to apply NetDecoder on each element in output?

I try to apply the NetDecoder on each output element but get an error. ...
user avatar
3 votes
1 answer
60 views

How to compile sum over the compiled expression?

Consider the following toy code: ...
user avatar
  • 3,542
1 vote
1 answer
90 views

How do we find the limit of my code?

Suppose we have the following: ...
user avatar
  • 199
1 vote
0 answers
79 views

How to fix Mathematica crashing in the following case?

I have a problem with Mathematica when trying to glue two tables together. The tables have the form ...
user avatar
  • 3,542
4 votes
1 answer
189 views

Speeding up Fourier transform and eigenvector calculation

I have a matrix $M$ in Bloch basis (momentum space). Then I have to take Fourier transform of $M$ to go to real space. The size of this lattice in real space can be fixed to some value $N_{unit}$. ...
user avatar
  • 601
3 votes
1 answer
181 views

Unbounded solution at boundaries with few combination of values in this BVP solution

I had asked a question here regarding solution to a BVP problem. bbgodfrey provided an excellent answer using the method of integrated least squares. However, for a few specific set of values of ...
user avatar
  • 143
1 vote
0 answers
56 views

Code review of my animation of Ellipsoid method

Feel free to suggest improvements (code-review) to my two functions (calculation and animation). They were made to visualize the workings of the Ellipsoid method in two dimensions. For example, see ...
user avatar
  • 612
0 votes
1 answer
81 views

How to fourier transform a numerical solution?

I numerically solved a wave equation and want to fourier transform the solution uwave1(t,x,z) at a particular instant of time t and position z. The code is as follows: ...
user avatar
  • 43
1 vote
0 answers
76 views

Shortest paths Knights Tour

I am trying to print the minimum steps needed to traverse a chessboard as a knight from one diagonal position to the other. I have the following code: Building the chessboard I started with creating ...
user avatar
0 votes
0 answers
59 views

My notebook backup function works fine. I am just asking for your critical review before submitting to FunctionRepository

Why the name and what does it do exactly? Youre probably asking yourselves why I named it NotebookBackupStack. All that is explained in ...
user avatar
  • 1,647
0 votes
1 answer
40 views

Updating the association with answers from the TrigProperties Function

I have created a list of rules I would like to update with values. My goal here is to be able to write the following: ...
user avatar
0 votes
1 answer
55 views

Check if a fraction leads to an integer, choose $r$ and run trough $0\le a\le n$ and go to $r+1$

Well, I am trying to do the following: I have two functions $y(r,a)$ and $z(r,a)$ and I want to check of the division of both those functions leads to an integer. In order to do that I want to choose ...
user avatar
  • 1,723
1 vote
1 answer
72 views

Outputting probability of rolling 6 dice N times, generating a new output each roll

I am looking to output the probability of n classic six-sided dice but I am not sure how to go about starting. This is what I have written out so far, but no way to go about accounting for n dice for ...
user avatar
1 vote
2 answers
55 views

Code should not evaluate at non-integers, fail at too few integers

I want this piece of code to sort a given list by odds first and evens last. This piece of code did the trick with the list I entered in: ...
user avatar
4 votes
3 answers
310 views

Checking if a number is right sorted

I have a number $n$ such that the digits of $n$ are strictly increasing to the left except for the first digit. So for example when $n=51369$ fits the bill because: $$1<3<6<9\tag1$$ Is there ...
user avatar
  • 1,723
1 vote
1 answer
60 views

How to create a flexible BarChart[ ] with Manipulate[ ]

This question is nothing more than making a few changes to an already working code. I put that code into Manipulate[...] to be able to choose a subset of countries ...
user avatar
  • 4,391
3 votes
1 answer
93 views

How to use RightComposition efficiently in the context of one-liners?

I find myself recently writting, more often than not, code that makes heavy use of RightComposition eg. expr//f/*g/*h It is relatively straightforward to first ...
user avatar
  • 122
0 votes
0 answers
40 views

Finding the limit of the average of a sequence?

...
user avatar
  • 199
1 vote
1 answer
71 views

How to dynamically link a bar chart to a table and present them in a single synchronized figure

This answer has addressed the question of presenting a bar chart and its data table together in a single figure. Not to repeat the same question, I should point out that the answer given is not ...
user avatar
  • 4,391
0 votes
1 answer
70 views

Parallelization in While[] loop when testing if a condition is met

Well, I am trying to run the following code: ...
user avatar
  • 1,723
1 vote
0 answers
66 views

Implementing the Binary GCD algorithm in Mathematica

Well, I have $n\in\mathbb{N}$ and I want to transform $n$ to a binary number which can be done using FromDigits[IntegerDigits[n, 2]]. I want to compute the ...
user avatar
  • 1,723
1 vote
1 answer
80 views

Parallel Mathematica-code that runs too slow when running PowerRepresentations[] function

Well, I am a student in elementary number theory and trying to find natural numbers that can be written as the sum of integers to the power of an integer. The code I am using now is the following: <...
user avatar
  • 1,723
0 votes
0 answers
44 views

Solving a system of equations (works with squares not with fifth powers)

Well, I was trying to solve a system of equations in a different question of mine. There @kglr gave a very efficient code for solving that system of equations using squares: ...
user avatar
  • 1,723
3 votes
1 answer
83 views

Removing a element from list when obeying a certain condition

Well, I have the following code: Select[PowersRepresentations[n, a, b], DuplicateFreeQ[#] && ! MemberQ[#, 0] &] This code finds ...
user avatar
  • 1,723
5 votes
3 answers
169 views

Permutation avoidance function

It is common for me to see if a permutation of 1,2,...,n, avoids some fixed permutation pattern. For example, the permutation [1,4,2,3,5] contains the pattern 1,3,2, as the elements [1,4,3] appear in ...
user avatar
1 vote
1 answer
75 views

how to draw a line at mean value of cross-section and time-series data using Bar Chart

I have Dataset; ...
user avatar
  • 4,391
1 vote
1 answer
81 views

how to perform operations on a subset of a dataset

I have this data set: ...
user avatar
  • 4,391
1 vote
1 answer
55 views

Data parallelism for independent probabilistic trials

I'm considering the best way to implement the data parallelism features of Mathematica for a specific task. To that end I have a minimal code example below which contains the basic features of my ...
user avatar
  • 271
0 votes
0 answers
95 views

Algorithms or Mathematica definition for functions ideals of polynomial Rings

This question was well posed four years ago without answer at Operations on ideals of polynomial rings. I asked again in Nov 2021 and posted possible function defininitions. Lichtblau commented ...
user avatar
4 votes
3 answers
250 views

How to differently color the two time series using two-Y-axes

I produced the following time series ListLinePlot: using the following Code (thanks to many of the contributors in this forum) <...
user avatar
  • 4,391
4 votes
0 answers
116 views

What do “Analyze Notebook" and "Analyze Cells" Do?

What does "Analyze Notebook" and "Analyze Cells" do? They seem to, at least, point out some coding errors that are already highlighted in a notebook. Do they do anything else? Is ...
user avatar
4 votes
1 answer
230 views

Using Mathematica to derive analytic form of single variable function

I am interested in finding an analytical form of the following function $f(n)$ defined as: $$f(n):=\sum_{\{\bar{K}\}}\prod_{l<j}^{n}e^{ik_lk_j},$$ where $\{\bar{K}\}$ is the full set of binary ...
user avatar
  • 271
4 votes
1 answer
104 views

Binary permutation list code in Mathematica

Given some natural number $N$, I am interested in the set of all binary permutations of length $N$ (with the intention of storing in lists depending on how many $1$'s appear in each permutation). My ...
user avatar
  • 271
2 votes
1 answer
149 views

How to draw a barchart with a vertical line

The following code works just fine with a few caveats. ...
user avatar
  • 4,391
0 votes
0 answers
29 views

Should Expanding a function result in changes to its Plot?

(Title needs improving) I'm trying to find the analytical expression for the attenuation of an AC voltage through a passive low-pass filter. The solution involves finding the time-dependent charge (<...
user avatar
2 votes
3 answers
149 views

What is the limit of the sum as `t` approaches infinity?

I am unable to find the limit of the following sum as t appraoches infinity ...
user avatar
  • 199
5 votes
1 answer
68 views

Individual block diagonalisations take more time than single diagonalization of block matrix

Sample Problem of a large block matrix: I want to find the lowest eigenvalue of a blockdiagonal matrix h[x] for a range of values of ...
user avatar
  • 902
0 votes
1 answer
30 views

How to resolve problem during summation of functions?

I am trying to find out the output of this basic problem but getting an error. If anyone can resolve this will be helpful. ...
user avatar
  • 83
5 votes
1 answer
162 views

Calculating the sum of means of lists as `n` approaches infinity

I am unable to calculate the sum for larger values of n. ...
user avatar
  • 199
3 votes
3 answers
152 views

How to produce {{1,40},{2,20}} from {{1, 10}, {2, 20}, {1, 30}}?

My attempt below produced a warning: Total::normal: Nonatomic expression expected at position 1 in Total[y]. ...
user avatar
0 votes
0 answers
67 views

Determining whether a matrix is in Jordan canonical form

At first, I was surprised that Mathematica doesn't have a built-in function for this, e.g. JordanMatrixQ. Anyway, we all know that a Jordan matrix is consisted of ...
user avatar
  • 789

1
2 3 4 5
9