If you are new to Mathematica, and were directed to this post, first see if you can use Table to solve your problem. I have often told people, especially beginners, to avoid using For in favour of Do....

You can use GatherBy for this. You can map List onto Range[...] first if you wish to have exactly the same output you showed. positionDuplicates[list_] := GatherBy[Range@Length[list], list[[#]] &...

I would like to make my graphics homogeneous with my (LaTeX) document. That means that I would like to use the same font in the graphics (labels for axis etc) as the main text. I recently wrote a ...

A preview Before I show any code, here's a preview of what is possible with some tweaking: First try Here's a go at implementing Wordle's layout algorithm, described at cormullion's link. First, let'...

LongestCommonSequencePositions and LongestCommonSubsequencePositions Their use is analogous to LongestCommon(Sub)sequence but they return the position of the first match instead. Update: These are ...

Update: Mathematica 10 has introduced Association, which can be used as a close equivalent of structs. params = <| "par1" -> 1, "par2" -> 2 |> params["par1"] (* ==> 1 *) In version ...

I found a robust solution described in this MathGroup message by Maxim Rytin: messageHandler = If[Last[#], Abort[]] & Internal`AddHandler["Message", messageHandler] This will abort the ...

There is no way to comment out a single line. Mathematica doesn't really respect lines, it pushes working at the expression level when possible (not at the source text level). Converting cells ...

High-level languages, like Mathematica, have a high overhead for executing each command/instruction. However, they also typically include commands/instructions that solve a larger and more complex ...

This is a general guide on debugging issues with parallelization performance. 1. Measuring performance The proper way to measure the timing of parallelized calculations is AbsoluteTiming, which ...

I wrote a package to automatically generate all the boilerplate needed for LibraryLink and for managed library expressions based on a template that describes a class interface: LTemplate Here's how ...

Update: This is now available as the BoolEval package. I recommend using L UnitStep[15 - T] for good performance. To answer your question about boolean indexing: When you write L[T > 15] = 0 ...

Here's a try: g3 = Graphics3D[{Gray, Sphere[]}, Lighting -> "Neutral", Boxed -> False] img = ColorConvert[Rasterize[g3, "Image", ImageResolution -> 72], "GrayLevel"] edge = ...

2014-04-12 NOTICE: MATLAB R2014a contains a bug that breaks MATLink on OS X and Linux (Windows is fine). If you use MATLink on OS X or Linux, please consider keeping MATLAB R2013b until R2014b comes ...

A more detailed guide on this topic is included in the MaTeX documentation, in the "Preparing Figures to Size" tutorial. Exporting graphics with consistent font sizes I'll show you my ...

I'm going to brute force it numerically. First, let's define the function we're interested in: fun = KnotData[{3, 1}, "SpaceCurve"] Imagine that this function fun[t] describes the position of a ...

The following answer is not complete, but does give one possible solution. There's a lot more to learn about the paclet manager, so please contribute another answer if you can, or correct this answer ...

MaTeX is a package made exactly for this purpose. It can automatically compile small LaTeX snippets and import them as Mathematica graphics. It is described in detail in this other Mathematica.SE ...

This behaviour has changed since that book was published. I am writing this additional answer to make it clear how Mathematica 9 searches contexts for symbols and that even the current version 9 ...

Here's a slow and concave version: blot[smoothness_: 20, points_Integer: 10] := With[ {fun = Exp[-smoothness #.#] &, pts = RandomReal[1, {points, 2}]}, RegionPlot[ Total[fun[# - {x, y}] &...

I second @Verbeia's suggestion: compute the function on a mesh of points and use ListContourPlot. The disadvantage is that ListContourPlot has no adaptive sampling, so it'd be preferable if we could ...

I was recently reminded that the following "functions" are settable, and I was surprised (even though I've seen this before). So I thought that it is valuable to share this information. There are ...

Warning: The SetSystemOptions method to detect failed compilation, described below, is not 100% reliable. Please see the comments (e.g. trC = Compile[{{a, _Integer, 2}}, Tr[a]] won't warn). I assume ...

In Mathematica 7 or 8, you can just use Tube. Please see the docs for many, many examples. Example: Show[ParametricPlot3D[{Cos[x], Sin[x], x/5}, {x, 0, 15}] /. Line -> (Tube[#, 0.2] &), ...

Parameters: a = -1.24458; b = -1.25191; c = -1.815908; d = -1.90866; Compiled function used for iteration: cf = Compile[{{pt, _Real, 1}}, {Sin[a pt[]] + c Cos[pt[]], Sin[b pt[]] + d ...

There is a Mathematica package exactly for this at the OEIS wiki. Somewhat related: there's also a package for formatting data into the OEIS format. WolframAlpha also has some of this information, ...

Update It turns out that the correct way is to use ExtendedDefinition, not ExtendedFullDefinition. Please see the answer by @jkuczm for a detailed explanation. This is a simplification of your ...

The behaviour you see is quite reasonable, given what we can expect from computer algebra systems. It will be very similar in other systems too (and exactly the same in all of Mathematica versions 8, ...