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

1
vote
0answers
42 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
80 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
49 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
95 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
45 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
68 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
119 views

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

I wish to implement the following recursion efficiently. ...
2
votes
0answers
48 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
79 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 ...
2
votes
0answers
47 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 ...
1
vote
1answer
64 views

Code check: Force simplified inequalities to be of form `expr > 0`

Simplify is a nice fast function that cleans up simple inequalities. For example: ...
3
votes
2answers
95 views

Partition a list dependent on consecutive list values

I have a list of 2D points which I partition every time the distance between consecutive list elements is bigger than a certain threshold. In a second step I select all the lists that start within a ...
0
votes
1answer
132 views

My Baum-Welch algorithm is very slow. Is it due to Mathematica?

I've also posted this question here, since I'm not sure which community is more adequate for this type of question. I've programmed imperatively the Baum-Welch algorithm for a 2 state hidden Markov ...
7
votes
1answer
132 views

Simpler code evaluating Dickman's function?

I've read here that Mathematica 10 can Obtain symbolic solutions to delay differential equations. Would that help in numericaly evaluating Dickman's function $\rho(u)$ ? It is a delay differential ...
10
votes
0answers
131 views

Segmentation of sunspots

I recently went for a walk with my camera and snapped a few pictures of the sun. The pictures didn't turn out too well, but this was to be expected without a telescope. I thought it might be a nice ...
1
vote
1answer
89 views

Passing function as argument

I've been mucking around with passing functions as arguments to other functions and via trial and error seem to have something that works. I was wondering if someone could have a quick look at some ...
12
votes
2answers
492 views

Parsing a CSV file using Interpreter

The new Interpreter functionality in version 10 looks like it has the potential to make parsing custom data formats very easy. I'm trying to create a CSV parser. ...
4
votes
3answers
220 views

Is there something wrong with this piece of code involving Manipulate?

I am playing around with the Manipulate sentence. I think the following code is right, and actually Mathematica 9.0 doesn't return any error message, but I am ...
1
vote
1answer
74 views

GUI->Text code conversion

I have to solve about 30 symbolic equations simultaneously. Mathematica is taking more than 24 hours to solve it on a 6 core system and now I have to run that on a cluster. In order to do so I need to ...
7
votes
1answer
238 views

Porting code from MATLAB

I'd like to switch from MATLAB to Mathematica for my research in digital signal processing. I used Mathematica a lot during the '90s but I haven't used it since then, so I might as well be a complete ...
1
vote
1answer
64 views

A code deal with Lists operation ---Needs optimizion

I have written some code to deal with lists, But the speed of the code is slow, Could Someone help me to speed up it? Probably could rewrite it with Functional Programming! Give me some ideas! The ...
0
votes
2answers
84 views

How can I name and manipulate several Input Fields? [duplicate]

I am completely new to mathematica--and have a very basic knowledge of programming. I would really, very much appreciate it if someone could explain to me how to refer to values entered into specific ...
1
vote
0answers
119 views

Nonlinear FEM and FindRoot

I'm trying to develop a kind of nonlinear FEM application using mathematica to solve a bvp like the following: $$ \gamma(u') ~u^{iv} + 2 \gamma'(u') u''' u''+ u''^3 = f(x) $$ where $u = ...
2
votes
1answer
146 views

How can I rewrite my code to make it simpler?

Two months ago,I written a function IRobot to caculate the $I_{xx},I_{yy},I_{zz}$ and $I_{xy},I_{xz},I_{yz}$,shown as below: ...
0
votes
2answers
70 views

Can `Array` work as `Loop`? [closed]

I got Mathematica code from my friend: ...
7
votes
1answer
148 views

Extract what symbol is set by SetDelayed, Set, TagSet, UpSet, SetAttributes, etc

One of the recent features of the Mathematica Plugin for IntelliJ IDEA (www.mathematicaplugin.halirutan.de) is a Structure View which let's you see information about several definitions that are done ...
0
votes
1answer
121 views

Better code for two variable fractal interpolation functions

I am trying to write code for 2-variable fractal interpolation functions using two iterated function systems and two starting functions (both $y(x)=x$) which creates a sequence of piecewise defined ...
1
vote
0answers
113 views

How to tweak the following purely numerical code

I am using the following numerical function in my program and I would like to speed it up. ...
0
votes
1answer
102 views

Dealing with nested lists

This question is strongly related to: Map and Apply a function on a nested list I am in a bit of a rut in terms of my MMA skills and looking to improve my coding. I've realized that rather than ...
22
votes
1answer
1k views

May the Fourth be with you

Happy Star Wars day. I was playing around with the image manipulation functions in Mathematica in an attempt to recreate the Star Wars crawl. There's an HTML/CSS implementation which is in my ...
6
votes
1answer
128 views

Path construction using `Nearest` shows ill behavior?

I have a dataSet that I'm trying to sort choosing a starting point and going to its nearest neighbor, and then to its nearest neighbor and so on. To do so, I've ...
0
votes
1answer
174 views

Mathematica Implementation of Householder’s Method

I typed the Householder code in this paper, which starts on page 7. The code is: ...
29
votes
9answers
4k views

Programming paradigm change

I'm new to Mathematica, I've been learning by myself, and, being a Java developer for some time, it makes it hard to adapt. I've tried to solve a Reddit challenge, and I came up with this solution: ...
0
votes
0answers
103 views

Constrained maximum likelihood

Trying to solve a MLE with nonlinear constraints that need to be satisfied. However, the given solution do not match the constraints. Am I doing it correctly? ...
1
vote
0answers
152 views

Runge-Kutta-2 on System

After spending some time using the Mathematica documentation and this Mathematica.SE answer, I implemented the Runge-Kutta-2 routines. I am hoping someone can validate what I did and tell me that it ...
2
votes
1answer
101 views

Performance on Binomial Deviate is slow

I hope I won't get spanked for reposting. This is related to a previous question discussed here: Performance on Multinomial Deviate is slow. but this version is simpler because it is a binomial ...
0
votes
2answers
84 views

Multiplying a list and randomly re-assigning that list to a series of numbers

I'm trying to write a script that matches a particular element to a coordinate. Let's say there are 24 coordinates; and that fractionally a:b:c:d:e is 18%:18%:18%:18%:27%. Instead of matching 4 of a, ...
6
votes
3answers
365 views

Mathematica style (drawing cubes)

I wanted to draw (lattice-aligned) unit cubes inside a sphere with a given radius centered on the origin, so I wrote this program: ...
0
votes
1answer
75 views

Generalizing Characters to n-character substrings [duplicate]

I'm doing some frequency analysis on an encrypted plaintext. Tally[] and Characters[] make the basic task quite easy. To count the number of times each character appears (sorted alphabetically; ...
0
votes
0answers
33 views

Check if a (possibly nested) list is real [duplicate]

I have a very large matrix of numbers. I want to check if all its entries are real. At the moment I am using realQ = And @@ Thread[Flatten[Im @ #] == 0] & Is ...
0
votes
2answers
162 views

How can I improve Do loop?

I have very large input of time series data (over 30000 observations) that look like as follows: ...
1
vote
2answers
155 views

Discretizing data using quantiles in Mathematica

I am trying to discretize a long array of real numbers into a uniformly distributed integer array. To do this I am identifying the quantile where each real value sits and writing it out to the output ...
2
votes
1answer
113 views

Optimizing my code to generate symmetric tensors

I have written code that does carries out the following task: Construct a fully symmetric rank-$P$ "tensor" out of a collection of user-input rank-1 vectors, and a rank-2 symmetric tensor $h$. The ...
3
votes
0answers
88 views

Optimizing a bubble art code [duplicate]

Based on that website I wanted to recreate the same effect using Mathematica but with any picture given by the user. Thus I came up with the following code: ...
0
votes
1answer
144 views

Graphics with shapefiles using tooltip

I'm trying to write a code that displays an entire shapefile color-coded by one variable, and then as the mouse is moving it shows the local regional area of interest with all its data Got a working ...
1
vote
3answers
187 views

professionalize/optimize my code that calls a function

I have the following construction, which defines a function that I subsequently call in a loop multiple times. I use this very often, but I have never looked into if there is a more professional way ...
0
votes
0answers
147 views

Code performance problem

Could anyone help me with the attached code? How would you speed up my attached code in some degree? Your comments are highly welcome. ...
0
votes
0answers
23 views

While loop not breaking when condition is met [duplicate]

I am having trouble with the while loop not breaking, ...
5
votes
1answer
211 views

Selecting a list from a list of lists

In working through Programming Paradigms Via Mathematica (A First Course) I have come across this two part question: A permutation of length "n" is a list of the first n positive integers in ...
2
votes
3answers
374 views

Making a multiple choice button

I've written the following code to create a multiple choice button that takes an arbitrary number of answer options and will assign a variable true/false depending on whether or not the correct choice ...