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
0 answers
48 views

Why this code does not show three legend lines?

My code shows empty legend lines. What should I do to show the graph with three legend lines? ...
Irram Riaz's user avatar
0 votes
1 answer
189 views

Fixing a code which covers $[-k,k]\times[-k,k]$ for a given $k\in\mathbb{N}$, with smaller rectangles of equal area?

Motivation: From this post we, initially, wanted to cover a rectangle using smaller, non-overlapping rectangles with the same area: the difference between the total area of the smaller rectangles and ...
Arbuja's user avatar
  • 29
3 votes
1 answer
165 views

Improve performance of Linear Optimization

EDIT I am reframing the question here by pulling out the relevant part about linear optimization, you can find the original question and the entire code down below. I am trying to increase the ...
Dotman's user avatar
  • 376
4 votes
4 answers
385 views

A simpler or more concise way to divide the boundary of a polygon into equal arc lengths?

I am really looking just for the least amount of code needed to do this but it is still readable. Here is the same polygon but the border is respectively split up into 10, 20, and 30 points along the ...
Teg Louis's user avatar
  • 445
1 vote
0 answers
162 views

How to show the limit of two functions in a code approach zero?

I don't know how to shorten the program, the entire code is required to understand everything: ...
Arbuja's user avatar
  • 29
1 vote
1 answer
61 views

How to join two disconnected curves with listplot

Actually I want to join the blue and the red curve with another curve (definitely not a straight line, but some smooth curve) to show the transition from blue to red. How can I do this? Please help. ...
Joy's user avatar
  • 43
2 votes
0 answers
51 views

Plotting diagram of complex equation [closed]

I have this equation: q1[t_] := -I*γ*Sin[θ] + ((γ*Cos[θ])/n^2)*(I*ξ[t]*y+z*α[t]) and the main code is the following with the definition of each parameters: ...
Ali Taher's user avatar
3 votes
1 answer
80 views

Why is StoppingTest in red? What other option to stop NDSolve?

The following stripped down code works, but I'm experiencing some strange warnings: from an old document made with Mathematica 7.0 (but used in version 13.2), I'm getting several warning messages ...
Cham's user avatar
  • 3,949
4 votes
3 answers
155 views

how to balance a matrix by proportional adjustment of rows and columns

Given a matrix: ClearAll[mat, refR, refC]; mat = { {21.2, 29, 19.9}, {9, 48.8, 22.4}, {49.8, 62.2, 7.8} }; I want to adjust the elements of ...
Tugrul Temel's user avatar
  • 5,303
0 votes
0 answers
51 views

Part specification error

I am doing a solved exercise shared here. However, while running the code, I encountered an error on page-8, under the Dynamics section. with error : I think this error is due to the absence of ...
user84456's user avatar
  • 1,502
1 vote
2 answers
119 views

Number operator

Suppose CR is my creation operator and AR is my annihilation operator. I have to show that ...
user84456's user avatar
  • 1,502
0 votes
0 answers
64 views

Mathematical Equations Puzzle: Perfect Sixes

pI have given the following problem to my students Write some code that solves the perfect sixes problem for all numbers it works for! The perfect sixes problem asks you to solve some equations: \...
Athanasios Paraskevopoulos's user avatar
1 vote
1 answer
95 views

How can I roll up a line to get a circle? [closed]

I am trying to transfer n1=4 points that I have on a line, on a circle. suppose: ...
Delaram Nematollahi's user avatar
1 vote
0 answers
96 views

Matlab to Mathematica code to solve system of ODEs [closed]

I have the following system of second order non-homogeneous DEs: \begin{align} 0 &= 2 x_t - J_{\pi_t}(x_t) \frac{\epsilon - 1}{\theta} (1 + \varphi) + \frac{\partial J_{x_t}(x_t)}{\partial x_t} \...
NC520's user avatar
  • 407
0 votes
0 answers
32 views

Discretizing Geographics

I am in need of boundary regions for cities. A previous question shows that it is possible to discretize CountryData: ...
bobthechemist's user avatar
0 votes
0 answers
52 views

How to solve Equation for different variable in Mathematica?

I want to solve the given equation for $(n=m=3)$ and I want the output variable $q_{1,1}, q_{1,2}, q_{2,1}, q_{2,2}$ Given Equation Given Equation-2 The output should be required Output Here is my ...
Muhammad's user avatar
2 votes
1 answer
89 views

Create a set of vectors from given pairwise dot product

Assume I am given a list of all the pairwise dot products of an unknown set of $n$ vectors. How can I efficiently generate such a set (or all possible sets) with the extra constraint that all vectors ...
AG1123's user avatar
  • 539
1 vote
2 answers
101 views

How to improve this plot? Behaviour of the derivative

I wanted to plot the function $$f(x) = \frac{x^2}{2} - 3\ln(\vert x\vert +2)$$ together with its derivative $$f'(x) = x - \frac{3x}{\vert x \vert(\vert x\vert +2)}$$ which exhibites a cusp point at $x ...
Enrico M.'s user avatar
  • 767
2 votes
0 answers
103 views

Placing shapes along a square spiral

Proposed code example is inspired by the main idea of this challenge. Wolfram Language provides great opportunities in computational geometry. But not all of them are equal in terms of speed and ...
lesobrod's user avatar
  • 1,085
1 vote
2 answers
72 views

Defining and executing large matrix operators on vectors efficiently

For an $N$-qubit system, I am interested in coding, in an efficient way, the following set of Kraus operators $\{A_c\}_c$ defined in the computational basis as \begin{align} \hat{A}_c := \sum_{m=...
John Doe's user avatar
  • 295
1 vote
1 answer
50 views

Roots of polynomial using sigmma notation (code improvement) and some maths related question

Comes from exploring roots of polynomials and using the recurrence relationship of $S_n = \sum \alpha^n$ notation. Like this: $$ S_2 = \left( \sum \alpha \right)^2 - 2 \sum \alpha \beta $$ where $\...
CasperYC's user avatar
  • 1,460
9 votes
1 answer
591 views

Mathematica for Theoretical Physics by Gerd Baumann : Henonmap

I was following a solved problem from the book mentioned below on the Henon map. However, even after correcting that I still get an error on execution. I am unable to find the exact cause. ...
user84456's user avatar
  • 1,502
1 vote
1 answer
142 views

Again with filling in a plot

I really don't understand how filling works, and here I am with a new question about. I need to colour the region in the first quadrant, created by the functions $x+2$ and $-3x+5$. Hence $x$ runs from ...
Enrico M.'s user avatar
  • 767
4 votes
1 answer
186 views

Collapse (hide) code inside a function

I often use structures similar to the "func" below, however I would like to be able to "hide" the function definitions (similar to cell grouping using a group opener). I think an ...
user8281's user avatar
  • 151
4 votes
1 answer
94 views

Speed up functions using variable types but not Compile

I am writing a large numerical code and I have set up many functions that take several arguments as input. In the functions I am using several built in Mathematica functions, such as Sum[], Part[], ...
Matteo's user avatar
  • 243
2 votes
1 answer
112 views

Unable to solve the given equation

I am trying to solve the given system in terms of $r$, for which I use the following code: ...
codebpr's user avatar
  • 899
1 vote
1 answer
163 views

Plot of massless particles on unstable null circular geodesic : Finding an alternative for Graphics`Mesh`FindIntersections and reducing code length

My friend and I were trying to reproduce Figure 4(left) from this paper(page 7). We succeeded in reproducing the result after writing a lengthy and complicated code. Here I dissect the code in steps: ...
codebpr's user avatar
  • 899
0 votes
1 answer
77 views

Trouble with output of Reduce as a root object for a 3d Plot

I am trying to find the value of $r_0$ using $L^2=\frac{{r_0}^3 f'({r_0})}{2 f({r_0})-{r_0} f'({r_0})}$ and making a 3d plot with the help of the code given below: ...
codebpr's user avatar
  • 899
4 votes
5 answers
186 views

Converting specific positions of a List into Sublist

Suppose I have a List of numbers: num = Range[5] I want to combine the second and the third element into a sublist to get the result as {1,{2,3},4,5}. I tried ...
codebpr's user avatar
  • 899
1 vote
1 answer
73 views

Implementing a way of generating binary data for use in a logistic regression

Background I want to generate a set of test data to be used in a logisitic regression. As an example consider the scenario where a cannonball is fired at a wall. There are only two outcomes: the wall ...
MOOSE's user avatar
  • 107
1 vote
1 answer
128 views

How to increase efficiency of Mathematica code?

I have a code that runs as it is supposed to, but it takes around 8 hours to reach the solution with the step size necessary to find agreement between the analytical and computational solutions. As I ...
Bill's user avatar
  • 31
1 vote
2 answers
126 views

How can I improve this code?

The code below is working well, but it's very slow in the Manipulate box. I know that the Do and AppendTo parts aren't very ...
Cham's user avatar
  • 3,949
1 vote
1 answer
79 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 ...
Patricio's user avatar
  • 563
0 votes
0 answers
71 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: ...
Arbuja's user avatar
  • 29
6 votes
4 answers
412 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: <...
Najib Idrissi's user avatar
1 vote
0 answers
70 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} ...
sam wolfe's user avatar
  • 4,187
0 votes
1 answer
91 views

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

...
qncw's user avatar
  • 1
3 votes
2 answers
105 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): ...
Jan Eerland's user avatar
  • 1,941
1 vote
1 answer
48 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 ...
Rescy_'s user avatar
  • 53
0 votes
0 answers
20 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 ...
Rescy_'s user avatar
  • 53
5 votes
1 answer
130 views

How to compile sum over the compiled expression?

Consider the following toy code: ...
John Taylor's user avatar
  • 4,984
1 vote
1 answer
103 views

How do we find the limit of my code?

Suppose we have the following: ...
Arbuja's user avatar
  • 29
1 vote
0 answers
99 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 ...
John Taylor's user avatar
  • 4,984
5 votes
1 answer
225 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}$. ...
Shamina's user avatar
  • 583
3 votes
1 answer
231 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 ...
Avrana's user avatar
  • 297
1 vote
0 answers
86 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 ...
Vepir's user avatar
  • 622
1 vote
1 answer
248 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: ...
Rescy_'s user avatar
  • 53
1 vote
0 answers
89 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 ...
Brandon Evans's user avatar
0 votes
1 answer
42 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: ...
Brandon Evans's user avatar
0 votes
1 answer
60 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 ...
Jan Eerland's user avatar
  • 1,941

1
2 3 4 5
10