Skip to main content

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

Using NetMeasurements for basic neural network

I have a neural network that works fine, but I would like to obtain some results on the Validation Set which provides some metrics on the performance of the training. I am obtaining some strange ...
John Doe's user avatar
  • 229
0 votes
0 answers
55 views

Improving accuracy of neural network for determining qubit rotation angle

The physics example problem (to illustrate the use of a basic neural network using Mathematica) I am looking at is a qubit rotated about the y-axis, where the rotation angle is discretized as $\...
John Doe's user avatar
  • 229
0 votes
2 answers
76 views

Generating lists where new elements depend on the previous element

I am interested in using some type of list or table in-built Mathematica function to generate a list, where the elements of the new list not only depends on the input values of a previously defined ...
John Doe's user avatar
  • 229
5 votes
4 answers
352 views

Still on Filling

I am really sorry to bother you for the same problems, but I cannot get in the view about this command, the filling option. What I want: to fill the semicircle part, under the $y = x$ curve. Here is ...
Enrico M.'s user avatar
  • 961
4 votes
3 answers
215 views

Vertical line: plotting and filling

I need some help to complete this code in order to make the wanted plot. In the following, the function that I define as $m(x) = 1$ should be replaced (if possible) to a function that plots a vertical ...
Enrico M.'s user avatar
  • 961
1 vote
1 answer
65 views

Adding list of error-bars to plot

I have a basic question about adding error-bars to a plot. It seems that the built-in errorbar function is no longer available, could someone advise on what would be an efficient way to include the ...
John Doe's user avatar
  • 229
2 votes
1 answer
56 views

Solving multivariable equation after setting partial derivative to zero

I have a real-valued function of four variables, namely $L[\phi, m0, m1, m2]$. I am interested in taking the partial derivative $\partial_{\phi}L$ thereof and setting the partial derivative to zero, ...
John Doe's user avatar
  • 229
5 votes
1 answer
212 views

Which NDSolve method is most effective for the given chaotic system?

Note: This question is for those chaotic systems where the order of maximal Lyapunov exponent is around $10^{-3}$. So it's different from normal chaotic systems like Hénon–Heiles system, Yang-Mills-...
codebpr's user avatar
  • 2,401
3 votes
1 answer
109 views

Problem with calculation of Lyapunov exponent

The code given by Chris K for Lyapunov Exponent does not work and gives lot of errors for the dynamical system given in equation(2) of this paper The dynamical equations: ...
Arssat's user avatar
  • 187
4 votes
1 answer
284 views

Recognizing a Higher Percentage of Multiple Barcodes from an Image

I would like a path or way to find barcodes in an image and read more of them and ideally quicker (It is very slow for an image). So, BarcodeRecognize[] already ...
Teg Louis's user avatar
4 votes
2 answers
117 views

How to call a list of pure functions/pure vector function? [closed]

In one dimension, pure functions work as usual: f = Function[{x}, 2 x] f[a] However, with a list of pure functions / a vector pure function this does not work with ...
faber's user avatar
  • 81
3 votes
1 answer
93 views

Quickly processing long lists using SequencePosition

Overview SequencePosition does exactly what I need; however, it seems to be very slow for long lists. Is there an input option that would allow it to process faster? Or, perhaps an alternative ...
user6546's user avatar
  • 1,069
4 votes
2 answers
184 views

How to improve the following code to get rid of the warning messages?

I have to solve the following initial Value problem $$y'=\frac{2xy}{y^2-1}, \quad y(2)=1$$ so, I wrote the following code to solve it ...
Athanasios Paraskevopoulos's user avatar
2 votes
1 answer
269 views

Can the result of the card dealing be displayed in a more aesthetically pleasing way?

The deck consists of 45 cards: one "2", one "A", three "K"s, and four of each other card ranging from "3" to "10", "J", and "Q". ...
csn899's user avatar
  • 4,335
1 vote
1 answer
61 views

Compressing a file's name string

I was working with files where each name records a lot of information about what is in its respective file and wanted to compress it a little bit. So I wanted to change it's 'base'. And I noticed that ...
Teg Louis's user avatar
4 votes
2 answers
270 views

Making geometries with Mathematica for use in Ansys

I am trying to model deformations caused by identical, solid half-ball bearings on a thin, solid cylindrical plate in Ansys. But drawing the geometries is much easier in Mathematica, especially if I ...
Teg Louis's user avatar
1 vote
2 answers
74 views

Numerical search of two simultaneous equations for three unknowns

Given the following two equations with three unknowns $\eta_1, \eta_2$ and $\tau$: $\frac{i e^{-i \phi/2}}{\sqrt{2}} = \cos(2 \tau - \eta_1 -\eta_2)\cos(\eta_1-\eta_2) - i\sin(2 \tau - \eta_1-\eta_2)\...
John Doe's user avatar
  • 229
0 votes
1 answer
96 views

Calculate The Declining Balance Method For Depreciation?

I have code generated by AI Aria in Opera browser The code gives wrong answer only for: Depreciation factor=1? ...
Mariusz Iwaniuk's user avatar
3 votes
1 answer
94 views

Indeterminate Lyapunov exponenet for four-wing attractor

We are using Chris K's answer on another question for finding Lyapunov Exponents for a dynamical system (Four-Wing Attractor) ...
user444's user avatar
  • 2,550
1 vote
0 answers
58 views

Why is GraphPropertyDistribution[.] taking an infinite amount of time to run?

This code is from the documentation: ...
Tugrul Temel's user avatar
  • 6,233
2 votes
1 answer
196 views

Python Code to Mathematica for Classical Map of Kicked Top

I am trying to convert this Python code for Classical map of kicked top to Mathematica. For a single trajectory, I am able to ...
user444's user avatar
  • 2,550
1 vote
0 answers
55 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
197 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
  • 71
3 votes
1 answer
221 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
  • 456
4 votes
4 answers
444 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
1 vote
0 answers
164 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
  • 71
1 vote
1 answer
69 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
54 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
87 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
  • 4,103
4 votes
3 answers
206 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
  • 6,233
0 votes
0 answers
54 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 ...
user444's user avatar
  • 2,550
1 vote
2 answers
146 views

Number operator

Suppose CR is my creation operator and AR is my annihilation operator. I have to show that ...
user444's user avatar
  • 2,550
0 votes
0 answers
79 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
112 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
104 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
  • 479
0 votes
0 answers
57 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
137 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
  • 571
1 vote
2 answers
102 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
  • 961
3 votes
0 answers
109 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,729
1 vote
2 answers
78 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
  • 229
1 vote
1 answer
64 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,642
9 votes
1 answer
637 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. ...
user444's user avatar
  • 2,550
1 vote
1 answer
152 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
  • 961
4 votes
1 answer
208 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
98 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
  • 283
2 votes
1 answer
115 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
  • 2,401
1 vote
1 answer
172 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
  • 2,401
0 votes
1 answer
82 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
  • 2,401
4 votes
5 answers
196 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
  • 2,401
1 vote
1 answer
85 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
  • 159

1
2 3 4 5
10