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
1answer
36 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
169 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
34 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
84 views

Partial comparison between lists contained in larger matrices [closed]

Please presume we have two nested matrices m1 and m2: ...
0
votes
1answer
130 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 ...
3
votes
1answer
57 views

sorting eigenvectors of a final combined matrix

I have two matrices m1 and m2 as below: ...
4
votes
3answers
118 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 ...
1
vote
2answers
73 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, ...
2
votes
2answers
162 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 ...
0
votes
1answer
119 views

Understanding simple code [closed]

Can anyone help me with how to understand the definition of the ExpandNCM function listed in the NonCommutativeMultiply ...
11
votes
1answer
144 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 ...
2
votes
1answer
433 views

converting Matlab program to Mathematica code

I have the following Matlab program; ...
6
votes
2answers
138 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: ...
0
votes
1answer
61 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 ...
0
votes
1answer
34 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$ ...
3
votes
1answer
52 views

Saving Dot-ed eigenvectors in a special comparison

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 ...
4
votes
2answers
95 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, ...
3
votes
0answers
74 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: ...
1
vote
1answer
61 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, ...
2
votes
0answers
48 views

Reducing quantile & color map queries for use with Associations

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: ...
5
votes
1answer
115 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 ...
1
vote
2answers
218 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, ...
0
votes
0answers
74 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. ...
0
votes
1answer
56 views
5
votes
0answers
162 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 ...
1
vote
0answers
136 views

How can I improve the solution of my PDE?

I want to improve the last code to find a better solution for umi. For now I'm using only MaxStepFraction. Also, when I put no ...
1
vote
1answer
137 views

Hill function (equation) vs a gene

So im trying to make one equation equal another to solve for all physically realistic values of $X$. Hill function is: $$ F(X)=\frac{1}{1+(\frac{X}{K})^n} $$ and Gene Z equation is: $$ Z(X) = ...
0
votes
1answer
40 views

Error message with Animate?

I have a error message, but after I execute ndsolve cell is all right.What is the Reason for this error? ...
2
votes
1answer
83 views

Plot directional field with a initial vlue

I do not have enough reputation to comment on other questions, hence I have to ask my own one I want to solve the following nonlinear first order ODE, $$(1 + x) (0.5 y[x]^{-0.5} (x - y[x])^{0.5} - ...
0
votes
1answer
47 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?
6
votes
1answer
141 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 ...
1
vote
2answers
106 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 ...
0
votes
1answer
81 views

usage of random numbers in recursive loop

I am trying to evalute two functions using iterative process as below ...
2
votes
2answers
84 views

Arrangements (?) from permutations of rows in a triangle, is there a simpler way to program this?

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

Matrix iteration failing after second step

I am calculating 11x6 matrix using different logics as in below code. Problem is in Do loop in below code where I have two different criteria to update matrix "fd". I am expecting logic in IF which ...
0
votes
1answer
77 views

Sampling Points Between Two Functions and Plotting Sample Points? (I have partial code) [duplicate]

I want to sample random points between $Cos(x)$ and $Sin(x)$ on $0 \le x\le \frac \pi4$ I was able to do graph the function here in Mathematica. I would like to count, and then plot points between ...
2
votes
4answers
222 views

How to make multiple if statements?

I know Mathematica's if format is If[test, then result, else alternative] For example, this ...
1
vote
1answer
71 views

How would I go about simulating conditional random birth 100 times?

So I have the following scenario: Assume you have this organism that reproduces by itself. An organism either reproduces 0, 1, 2, or 3 organisms at a time. Assume they're asexual and reproduce only ...
1
vote
3answers
426 views

How to simplify and shorten pattern code?

I this code to sorting only those tuples that are have total sum of 15 without repetition.: ...
0
votes
0answers
74 views

Optimising prime number test code

Is it possible to speed-up this code ? Also, It would be great if people could test this algorithm. I only have a Raspberry Pi to test it on, so I can't be certain it's not a strong probable prime ...
13
votes
7answers
823 views

How to sort digits in a string while keeping other characters untouched?

Now there is a string with digits and letters, for instance, "95uge678r3gi89hgfe30kgh063d51". And the expected output is ...
0
votes
1answer
75 views

Tutorial for Map, Apply, etc

I have this code: ...
0
votes
0answers
90 views

How to eliminate all terms of a variable with square root in an equation?

I did the following thing: take an equation with square root terms, by moving terms and squaring two sides, finally ending up with a polynomial of the specific variable. My algorithm is like this: ...
3
votes
1answer
146 views

How to accelerate my code?

Given a 2D $M \times N$ matrix with non-negative values, I would like to find a path going from top to bottom such that the sum of the path is minimum. My function is defined as follow: ...
1
vote
0answers
178 views

Collision detection algorithm (discrete) with sweep and prune algorithm for periodic boundary conditions

EDIT: Question Updated with solution approach, but solution much slower than original implementation. Any ideas to speed up implementation? In the discussion on collision detection (see here) I asked ...
4
votes
2answers
201 views

Finding large Collatz Sequences, trying to improve speed

Background: I am already very much in love with Mathematica but I am also a novice. So far I have only gathered experience in procedural programming in Python. Generally speaking I am trying to ...
0
votes
1answer
72 views

Solving coupled ODEs with NDSolve

Given the system of differential equations: $i\frac{d}{dt}c_{1}(t)=H_{12} E(t)e^{(iw_{12}t)}c_2(t)+H_{13} E(t)e^{(iw_{13}t)}c_3(t)$, $i\frac{d}{dt}c_{2}(t)=H_{21} E(t)e^{(iw_{21}t)}c_2(t)+H_{13} ...
0
votes
0answers
53 views
10
votes
1answer
393 views

How to visualize pattern matching process?

I want a function that does the same job like ReplaceRepeated, and can make the matching process visible. I searched the Internet but didn't find any existing code ...
7
votes
2answers
207 views

Efficient Lloyd Sampling of Images

I want to sample a grayscale image so that every voronoi cell contains approximately the same total intensity using lloyd sampling. My current code is kind of slow and I was hoping for some advice to ...