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

28
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: ...
22
votes
7answers
991 views

Splitting words into specific fragments

I am looking into splitting words into a succession of chemical elements symbols, where possible. For example: Titanic = Ti Ta Ni C (titanium, tantalum, nickel, carbon) A word may or may not be ...
21
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 ...
21
votes
1answer
575 views

Strategies for solving problems involving searches

As an example of a search-oriented problem, consider finding all constrained $n$-colorings of a graph. An "$n$-coloring" associates one of $n \ge 1$ colors to each vertex in such a way that no edge ...
17
votes
1answer
319 views

Copying one symbol into another

I would like to know how can I completely copy one Symbol to another. When I say copy, a refer to UpValues, DownValues, ...
16
votes
0answers
624 views

Fast Spherical Harmonics radiative transfer

This is a rather specific question and I apologize for spamming you with some lengthy code. But it could be interesting for some reader and maybe you can help out, so please bear with me. I am using ...
14
votes
1answer
1k views

Poisson solver using Mathematica

I am looking for some help with a Poisson solver I am writing in Mathematica. The code is quite long with Arrays plugged in, so the full details can be found at http://pastebin.com/uSrSDcW6 I am ...
13
votes
9answers
561 views

Thread over list in different levels

I have these two lists, both with the same length in the first dimension: ...
13
votes
4answers
422 views

Button evaluation inside DynamicModule

Someone know why this Button works when clicked: ...
11
votes
2answers
295 views

Clever use of DownValues, or failure to understand the “Mathematica Way.”

I needed to look at the changes in the values of about 4000 items from one year to the next. I have a table with identifiers and values for each year. Not all of the items are in each list. The ...
11
votes
2answers
509 views

What's the most “functional” way to do Cholesky decomposition?

I can do Cholesky in a procedural style, such as: ...
11
votes
3answers
519 views

Simpler way to fill date gaps with zero values

One basic problem when working with data like sales and dates is the case where you dont't have sales in all days, so you have to fill it to take information as average or to make a plot. See this toy ...
10
votes
2answers
423 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. ...
9
votes
1answer
407 views

TemporalData frequency option as in R

I'm studying R, and am very impressed by the simplicity of some commands and in the way R handles temporal data. For example, in R, if you have some one-dimensional temporal data, you can easily ...
8
votes
2answers
694 views

Speed up Mathematica code involving Convolve

I'm trying to plot the averaged autocorrelation function of a random wire profile $\xi(x)$ which is build from unitsteps which are each L units long. To calculate the average I'm generating nMax ...
8
votes
2answers
428 views

Feedback on Functional Programming: Propagation of uncertainty

Lately I've been trying to use functional prgramming and tried to implement the gaussian propagation of uncertainty (without correlation) in an elegant way, here is the outcome: ...
8
votes
0answers
79 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 ...
7
votes
4answers
559 views

Loop optimization

I wrote this to generate a 6D distribution of particles. ...
7
votes
1answer
219 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 ...
7
votes
1answer
123 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 ...
6
votes
2answers
148 views

Looking for feedback on this function

I'm not sure this is an appropriate question; if not, I'm sure someone will close it :) I've got the following function, listed below; its job is to accept a graph (function) presented either as a ...
6
votes
3answers
327 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: ...
6
votes
1answer
126 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 ...
6
votes
1answer
126 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 ...
6
votes
2answers
763 views

Elegant way to handle columns operations

Inspired by this question from @sjdh and by my recurrent use of columns operations in database sets, I was looking for one way to make columns operations more symetric, so I can handle with matrix and ...
5
votes
2answers
537 views

How to create a simple interface to get file path and execute some code on it?

I need to create a simple user interface to choose one file in the notebook directory, import it and execute some functions on the imported data. For the first version I created this code: ...
5
votes
1answer
190 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 ...
4
votes
6answers
1k views

Why is this Mandelbrot set's implementation infeasible: takes a massive amount of time to do?

The Mandelbrot set is defined by complex numbers such as $z=z^2+c$ where $z_0=0$ for the initial point and $c\in\mathbb C$. The numbers grow very fast in the iteration. ...
4
votes
3answers
207 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 ...
4
votes
1answer
237 views

Symbolic bit vectors

I'd like to see how addition and xoring bitvectors mix together. To do this, I implemented (a primitive) vec_add and vec_xor: ...
4
votes
2answers
915 views

How to fix BodePlot that comes with Mathematica?

I am using Mathematica to go through the examples and exercises on the book Modern Control Systems, 6th edition by Dorf. On page 605, there is a table (Table 8.5) with the Bode plot for several ...
4
votes
1answer
123 views

Copying a symbol using a subpackage

In this question, there is a beautiful method to copy a symbol. However, i'm not able to use it as an addon to my package. So the main question is How to rename/copy a function defined in a ...
4
votes
1answer
168 views

Feedback on my Subscript code

I have written a code, and I need a little feed back.. I want to make the Subscript distributive across (1) addition and (2) multiplication to mimic short-hand for ...
3
votes
3answers
529 views

Speed optimization

I have a part of a program that I have to repeatedly call many times (about 2000 to 10000 times) ...
3
votes
1answer
101 views

Best way to transform text into number in a big array

I have a big array of data that I imported from a lot of XML files. To get the data, among other manipulations, I use this function: ...
3
votes
1answer
492 views

Function to Determine Lucky Numbers

Given a list of the form {1, 3, 5, 7, ...}, the lucky numbers are obtained by looking at the first list element after 1 (so 3 in this case), and deleting all list ...
3
votes
1answer
286 views

How to improve this dynamic progress bar code

I created this progress bar to use in my codes: ...
3
votes
0answers
85 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: ...
2
votes
3answers
692 views

Using DSolve to solve for x[t,parameter]

I'm trying to solve an ODE with two independent variables (a cannon firing from a cliff incorporating wind resistance dependent on velocity). I've tried the following for the x-component: ...
2
votes
1answer
512 views

3 hour calculation? ParallelMap & ParallelTable

I'm having some problems with slow Mathematica code... I'm basically doing a computation that's is expected to take 3 hours (!) in my Core i7 with 4 processors... I'm basically computing an index (of ...
2
votes
3answers
337 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 ...
2
votes
1answer
162 views

EmpiricalDistribution for Gini Coefficient Runs Slow

I am repurposing code that I found in this blog post (http://datavoreconsulting.com/sports/gini-coefficients-and-the-olympic-medal-race/) to generate the Gini coefficient for other data sets I am ...
2
votes
1answer
143 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: ...
2
votes
1answer
64 views

Unique[] in RHS of rule

I have a function, explicit that takes dot product of two symbols, and replaces it with repeated dummy indices generated by ...
2
votes
1answer
85 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 ...
2
votes
1answer
99 views

Writing a function to mimic Characters

I am working my way through Programming Paradigms via Mathematica (A First Course) and have answered the following question in lesson 25: Write a function of one argument "s", a String, which ...
2
votes
1answer
100 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 ...
2
votes
1answer
169 views

How to override `?NumericQ`

I have a function myFunc which I is to be displayed cleanly if arguments are symbolic, but which can also be numerically evaluated. I do this by defining a ...
1
vote
3answers
176 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 ...
1
vote
1answer
63 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 ...