40
votes
2answers
1k views

Head and everything except Head?

I have been working on picking expressions apart using Head and Part and encountered a little mystery. Consider the canonical ...
23
votes
1answer
374 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 ...
19
votes
5answers
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 ...
19
votes
3answers
936 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 ...
6
votes
3answers
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 ...
20
votes
3answers
554 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 ...
14
votes
2answers
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 ...
13
votes
6answers
2k views

Replacing composite variables by a single variable

To replace a single variable by another variable, one can simply use the the replace all (/.) operator (e.g., ...
8
votes
4answers
659 views

Problem with ContourPlot

I tried these ...
9
votes
2answers
641 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 ...
7
votes
2answers
902 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 ...
6
votes
3answers
1k views

Using D to find a symbolic derivative

I need to do the following: Define a function Take the derivative of this function and have a look at the symoblic representation Substitute in some values With the bonus that I want to use the ...
419
votes
6answers
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 ...
35
votes
3answers
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 ...
53
votes
5answers
3k views

Minimal effort method for integrating C++ functions into Mathematica

As of Mathematica 8, what is the minimal effort way to integrate an existing C++ function into Mathematica? I think we have these: MathLink (it was quite long ago I used it last time) communication ...
49
votes
3answers
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 ...
47
votes
1answer
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 ...
31
votes
2answers
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, ...
26
votes
4answers
587 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 ...
20
votes
4answers
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 ...
35
votes
4answers
2k views

Point Renderings Slightly Off in Mathematica

The Mathematica code ...
16
votes
2answers
1k 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 ...
15
votes
3answers
365 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}] ...
20
votes
1answer
410 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 ...
25
votes
4answers
990 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]) ...
24
votes
2answers
2k views

Generating a broken or snipped axis in ListPlot

I have two data sets, data1 and data2. For example: ...
20
votes
3answers
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: ...
17
votes
3answers
588 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 ...
16
votes
3answers
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: ...
13
votes
1answer
524 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: ...
25
votes
2answers
926 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 ...
11
votes
3answers
355 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 ...
10
votes
1answer
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: ...
13
votes
1answer
359 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 ...
7
votes
2answers
962 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 ...
33
votes
3answers
3k views

Calling MATLAB from Mathematica

How can I call MATLAB functions directly from Mathematica and transfer data/variables between the two systems?
24
votes
3answers
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:
24
votes
4answers
944 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 ...
34
votes
5answers
642 views

Placement of Condition /; expressions

It is my practice to place Condition expressions on the left side of := and :> in almost ...
25
votes
2answers
769 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?
25
votes
5answers
849 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.
22
votes
3answers
702 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 ...
26
votes
4answers
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 ...
25
votes
4answers
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 ...
25
votes
4answers
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 ...
20
votes
3answers
1k views

“Covering up” text in Graphics

Consider the following code: ...
15
votes
6answers
4k views

About multi-root search in Mathematica for transcendental equations

I have some questions for multiroot search for transcendental equations. Is there any clever solution to find all the roots for a transcendental equation in a specific range? Perhaps ...
18
votes
4answers
2k views

Can 2D and 3D plots be combined so that the 2D plot is the bottom surface of the 3D plot boundary?

I have a ListlinePlot function, that I would like to combine with both a Graphics3D plot and a ...
11
votes
3answers
360 views

Custom functions by delegating options in a specific way and using core functions

I'd like to create a custom function that does essentially the same as a core function of mathematica but uses different default settings. Example: I want a Plot function that uses Mathematica's core ...
9
votes
5answers
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 ...

15 30 50 per page