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

0
votes
0answers
18 views

being a function in a multiple steps and using syntax for being shortened

My desire is to access to a table with the bellow construction: Table[desired[t], {t, 0, 2, 0.1}] For achieve to desired[t] ...
1
vote
2answers
146 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
56 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
49 views
5
votes
0answers
73 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
93 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
105 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
32 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
35 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
85 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
92 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
63 views

usage of random numbers in recursive loop

I am trying to evalute two functions using iterative process as below ...
2
votes
2answers
72 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
44 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
201 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
386 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
60 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
770 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
60 views

Tutorial for Map, Apply, etc

I have this code: ...
0
votes
0answers
53 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
134 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
93 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
93 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
60 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
360 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
185 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
58 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
115 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
403 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
77 views
3
votes
2answers
138 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
194 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
255 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
80 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
106 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
73 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
186 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 ...
1
vote
1answer
122 views

C compiler error: the no library could be generated error

I have windows 8, Mathematica 9, and I've just installed Microsoft Visual Studio 2013 with update 3. I'm try to run Compile with the option ...
3
votes
1answer
133 views

How to remove recursion, and write it functional and efficient way?

I wish to implement the following recursion efficiently. ...
2
votes
0answers
53 views

Number recognition in Mathematica [closed]

Suppose that I have a number $n$ with many decimal digits of precision. What is the code to use to get Mathematica to recognize possible closed-form expressions for that number?
0
votes
1answer
92 views

How to compute an integral with 300 digits accuracy [closed]

I'm new to Mathematica and I would like to ask what is the code to use to calculate numerically an integral with 300 digits precision; also, I would like to know what is the right code to use the ...
6
votes
0answers
107 views

Fine tuning compiled code that computes dilogarithm function

As an exercise of writing a good Compile function, I want to do the simple task of coding a routine that outputs the real part of the dilogarithm function ...