All Questions

3k views

Creating Mathematica packages

I'm building a package to help me write packages and their documentation. In this post I explained how to make a package and its documentation. In the answer I provided I describe how to build a very ...
1k views

Partition a set into subsets of size $k$

Given a set $\{a_1,a_2,\dots,a_{lk}\}$ and a positive integer $l$, how can I find all the partitions which includes subsets of size $l$ in Mathematica? For instance, given ...
2k views

Extract current viewing parameters from a 3D view?

Is there a way to find out the current viewing parameters of a 3D view? What often happens is that I create a view, for example: ...
3k views

What is the most efficient way to add rows and columns to a matrix?

Say I have a matrix m and a vector v. ...
1k views

I have been working on picking expressions apart using Head and Part and encountered a little mystery. Consider the canonical ...
375 views

What can be used as the second argument to Return on your own functions?

Having found out about the second argument to Return I played a bit with it, and the following tests all resulted in ...
1k views

Can I simplify an expression into form which uses my own definitions?

This seems like a simple thing to do, but I couldn't find anything relevant from Mathematica documentation. So suppose I have an expression: a*b/(a + a*Cos[a/b]) ...
1k views

How to pass a symbol name to a function with any of the Hold attributes?

Given a function with the attribute HoldFirst, HoldAll or similar, and a variable, list, how ...
943 views

How to load a package without naming conflicts?

This question applies to any package, but I encountered this problem while working with graphs. There are symbols in the Combinatorica package (such as ...
2k views

Assigning values to a list of variable names

As part of a calculation I need to do something like this Evaluate[{aaa, bbb, ccc}[[ index]]] = {1, 2, 3, 4, 5} so if index is ...
560 views

Common subexpression from two expressions

I am working with some unpleasantly tedious polynomials, which need to be manipulated in various ways (integrate with respect to some variable, differentiate with respect to another). Since these ...
1k views

How to fit 3 data sets to a model of 4 differential equations?

I'm a biologist and a newbie in Mathematica. I want to fit three data sets to a model consisting of four differential equations and 10 parameters. I want to find the parameters best fitting to my ...
530 views

Funny behaviour when plotting a polynomial of high degree and large coefficients

I am trying to plot a polynomial of degree 29 on the domain [0,1], with fairly large coefficients: ...
799 views

What is the difference between Set and SetDelayed?

I have a problem with defining a function and most of time I get confused by Set or = and ...
654 views

Usage of Assuming for Integration

For some reason, when I enter the following integration in Mathematica Assuming[{k ∈ Integers}, Integrate[ Exp[ I k t], {t, -π, π}]] the result turns out to be ...
910 views

ParallelTable and Table do not give same result

I have a question regarding the use of Parallelize. In the help one can read that “Parallelize[Table[expr,iter, …]] (which is ...
154k views

xkcd-style graphs

I received an email to which I wanted to respond with a xkcd-style graph, but I couldn't manage it. Everything I drew looked perfect, and I don't have enough command over ...
3k views

Metaprogramming in Mathematica

Being functional, and having no "quotation", i.e. essentially treating data and programs semantically same, Mathematica seems naturally capable of doing metaprogramming. But could anyone construct a ...
4k views

Recovering data points from an image

Unfortunately, some data can only be obtained in picture form (Japanese publications anyone?). Since this cannot be worked with, it has to be converted to a dataset that can; I was wondering whether ...
3k views

Torn edge paper effect for images

In my answers to Plotting Error Bars on a Log Scale I used a so called "torn edge" effect from on one of the images. @SjoerdC.deVries commented: "BTW I liked the ripped-out look of your InputForm ...
3k views

Plotting implicitly-defined space curves

It is known that space curves can either be defined parametrically, \begin{align*}x&=f(t)\\y&=g(t)\\z&=h(t)\end{align*} or as the intersection of two surfaces, ...
588 views

How to make MapAt work with Span?

Span (;;) is very useful, but doesn't work with a lot of functions. Given the following input ...
703 views

Resource management in Mathematica

I am using a library that has functions like createSomeObject[] and deleteSomeObject[obj]. It is an interface to a C language ...
2k views

Point Renderings Slightly Off in Mathematica

The Mathematica code ...
1k views

Generating evenly spaced points on a curve

In the KnotData package a simple command such as points = Table[KnotData[{3, 1}, "SpaceCurve"][t], {t, 0, 2 Pi, 0.1}]; will ...
2k views

Open Excel file with Mathematica

I would like to open an Excel file and manipulate it as a COM object. While I'm able to open an instance of excel with ...
366 views

How can I get the unchanged Box form of an arbitrary expression?

One may observe that MakeBoxes does not give the actual Box form of various expressions: MakeBoxes[{1*^4, 000123, a*b c}] ...
413 views

How can I make threading more flexible?

Threading automatically with Listable functions requires the argument expressions to have the same length (or for one of them to be atomic). For nested lists the ...
2k views

Generating a broken or snipped axis in ListPlot

I have two data sets, data1 and data2. For example: ...
1k views

Reading periodic elements from a large file

I have a large binary data file (big endian) with 100+ million "rows" of 11 elements, combination of floats and integers. This is the format: ...
591 views

Optimising 2D binning code

I have a set of (x,y,z) data, 45,000 to be precise and I want to bin the z values in 256 equidistant bins based on their (x,y) values. The final array should be a set of 256x256 array with each slot ...
2k views

How to find rows that have maximum value?

Suppose if I have following list { {10,b,30}, {100,a,40}, {1000,b,10}, {1000,b,70}, {100,b,20}, {10,b,70} } How to find rows that have max value in ...
2k views

Way to improve “show me this decimal number to M places, don't use scientific notation”?

The best way I can come up with to say "show me this fraction as a decimal number to M places, don't use scientific notation" is: ...
934 views

Meaning of backtick in floating-point literal

If I compute, say, 1/3//N, Mathematica displays 0.333333 as the result. When I copy that output to use elsewhere, the paste ...
359 views

Why do buttons with ChoiceDialog freeze the front end?

Pressing the button below will freeze my front end. An unpainted white dialog box comes up, then it completely freezes, and I need to forcibly kill the front end. CPU usage stays at zero during ...
1k views

Combined numerical minimization and maximization

I want to numerically calculate the maximum of a function defined by the minimization of another function, like the following: ...
360 views

Using Evaluate and Evaluated -> True in Plot

A few use cases: (1) This, as expected, returns (almost) immediately: f[x_?NumericQ] := Evaluate[(Pause[1]; x)] Plot[f[x], {x, 0, 1}] (2) This takes ...
976 views

Create complicated text formulas in graphics

I want to put somewhat complicated, or at least non-standardly formatted, text on some of my graphics. For example, I'd like to be able to use f^[4](x) (where the ...
3k views

Calling MATLAB from Mathematica

How can I call MATLAB functions directly from Mathematica and transfer data/variables between the two systems?
3k views

How to find circular objects in an image?

How could I use morphological processing to find circular objects in an image? More specifically, I need to detect road signs. I need to get the "80 speed limit" sign from this image:
948 views

Compiling more functions that don't call MainEvaluate

I would like to use Compile with functions defined outside Compile. For example if I have the two basic functions F and G F[x_] := x + 2 G[x_] := x And I want ...
643 views

Placement of Condition /; expressions

It is my practice to place Condition expressions on the left side of := and :> in almost ...
1k views

Map a function across a list conditionally

It seems that this is a really basic question, and I feel that the answer should be obvious to me. However, I am not seeing. Can you please help me? Thanks. Suppose I have a list of data ...
864 views

What is the complete list of valid Front End Tokens?

What is the complete list of valid Front End Tokens? Preferably, by version number.
770 views

Can a Trie be implemented efficiently?

What is the most space and time efficient way to implement a Trie in Mathematica? Will it be practically faster than what is natively available in appropriate cases?
704 views

Prepend Information to Warning Messages

I have a function running within a Do loop that sometimes issues a warning. I'd like to prepend the warning with the loop ctr so that I can go back and debug that instance later. Basically, I would ...
3k views

Density plot on the surface of sphere

I would like to make density plots of a list of (size 2 or 3) spherical harmonics on the surface of a sphere. I'd like to plot it so that each element of that list is using a different color (red ...
1k views

Aborting evaluation when the memory exceeds a certain limit

Sometimes when generating a lot of data the memory usage shoots beyond its physical realm and my laptop freezes. There is no way to stop Mathematica when this happens. Task manager (or its equivalent ...