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

3
votes
0answers
16 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 ...
3
votes
2answers
72 views

How to define UpValues about the derivative of NBSpline when the length of knots is unknown?

Description In the book “Programming in Mathematica” 3rd by Roman.E.Maeder, the author gives a topic about A new Mathematical Function in section 8.4. For instance, for the following formula: ...
3
votes
0answers
58 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
47 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, ...
1
vote
0answers
39 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
107 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
159 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
60 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
51 views
5
votes
0answers
84 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
98 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
112 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
33 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
56 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
39 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?
5
votes
0answers
87 views

How can I do a two dimensional `Fold`?

I'd like to Fold over higher dimensional objects than lists. Semantically, the format would be something like ...
1
vote
2answers
96 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
67 views

usage of random numbers in recursive loop

I am trying to evalute two functions using iterative process as below ...
2
votes
2answers
73 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
67 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
48 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
205 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
68 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
393 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
62 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
780 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
63 views

Tutorial for Map, Apply, etc

I have this code: ...
0
votes
0answers
56 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
137 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
102 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 ...
3
votes
2answers
105 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
61 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
39 views
10
votes
1answer
367 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 ...
6
votes
2answers
191 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 ...
1
vote
1answer
59 views

Is this caused by meomory usage ? (Something odd/hard to describe)

I really can't make a "smaller" example, but the files are here, for the data and for the notebook. It will cost a LOT of memory, up to 30G of RAM (maybe more). Here is the problem, (from a Linux ...
0
votes
0answers
50 views

How to Fold (FoldList) this in a more compact (efficient) way?

Example code: x = Table[something[i], {i, 5}] Table[Fold[f1[#1, f2[#2, a], a] &, x[[i]], {c1, c2, c3}], {i, Length[x]}] This above is just an example. I ...
1
vote
1answer
122 views

How to rewrite a nested loop with Reap and Sow [closed]

I was wondering if anyone know how to rewrite the following nested loop but using Reap and Sow. I need to reduce the execution time. Thank you. ...
5
votes
2answers
405 views

Code elegance and compactness. Help needed with Map, Apply

I need some help with code optimization and compactness. I have a set of two-dimensional points and I can use the Mathematica function FindClusters to find 4 clusters. I'd like to plot the points ...
2
votes
1answer
80 views
3
votes
2answers
145 views

How to deal with the condition that a function own many options?

Assming that I have a function myFunc which has some options. ...
4
votes
2answers
195 views

Generate lists that satisfy a condition in an efficient way

The following code produces lists of sublists with maximum length 5 that shuffle zeros around an ordered list (here {1,2}). It produces all permutations while ...
1
vote
1answer
268 views

Lookup construction using data matrix and Reap/Sow versus AppendTo`s

I am a user of MMA9 and made my own kind of Lookup, which is now a standard command in Version 10. In my program there is a section in which by means of a StringReplace[ ]-command containing a lot of ...
1
vote
0answers
82 views

Am I simulating correctly my hidden markov chain?

I want to simulate a hidden markov model, in which $y_t|y_{t-1},x_t=i \sim N(\theta_0y_{t-1}+\theta_i,\sigma^2)$, where $y_t$ is the observations or data, and $x_t$ is the state variable of the ...
1
vote
0answers
60 views

Problem with converting recursive code to iterative

I am trying to convert a snippet that uses recursion into one that uses iteration for drawing an L-tree, but my code produces duplicate points. How do I avoid generating them? Recursive version: ...
1
vote
1answer
108 views

Plot multiple solutions [duplicate]

I want to plot multiple solutions of an equation, so that one can differ them in the plot. The given equation is e.g. ...
2
votes
0answers
75 views

Better way to compute triple (or higher order) convolution

I have an identity that I want to verify. $$\sum_{i+j+k\ge ...
0
votes
1answer
196 views

Optimizing Chi-square distance between two distribution

I want to program the chi-square between two distribution Xu and Vu with length N. This function is defined as below: Xu and Vu are real and positive. ...
1
vote
0answers
55 views

Implementing normalization/rescalement from a Tutorial

I'm trying to implement a rescale/normalization as is described in here by mathematical expressions in page 10, and code in the top part of page 16. The notebook is also available here. The objective ...