All Questions

12
votes
2answers
486 views

Unexpected behavior of rule matching a pattern

I am a beginner exploring the world of Mathematica. I expected the following code T[6, 5, 4, 1, 2, 3] /. {T[a___, 1, b___] -> Length[List[b]]} should return ...
60
votes
10answers
3k views

How to “Copy as Unicode” from a Notebook?

I spent some time manually editing a post replacing Mathematica ASCII \[Alpha] with Unicode α. I did this by laboriously ...
37
votes
6answers
2k views

Mathematica Destructuring

Context I'm writing a function that look something like: ...
36
votes
7answers
4k views

How to differentiate formally?

I have been wrapping my head around this for a while now and I have not found a solution so far. I want to work with an arbitrary number of variables in Mathematica and use some built in functions. To ...
26
votes
4answers
26k views

How do I identify the source of a “Tag times protected” error?

I have some code that looks like Table[ a = 1; b = {2, 3} c = i;, {i, 2} ] which gives an error: Set::write: Tag Times in c {2,3} is Protected....
92
votes
2answers
4k views

Is it possible to define a new PlotTheme?

In version 10 one can define, say, $PlotTheme = "Scientific" Which changes the appearance of all plots. This is fantastic because on the one hand I can have nice ...
69
votes
6answers
5k views

Does Mathematica have advanced indexing?

I have two $M \times K$ arrays $L, T$ where I would like to set all the elements in $L$ to zero whenever the corresponding element of $T$ is greater than 15. The ...
37
votes
9answers
5k views

Removing elements from a list which appear in another list

There are two lists {a, b, c, a, d, a, e} and {a, c, a}. I need to remove those elements from the first list which appears in a second list, to get {b, d, a, e}
47
votes
5answers
15k views

Multivariable Taylor expansion does not work as expected

The basic multivariable Taylor expansion formula around a point is as follows: $$ f(\mathbf r + \mathbf a) = f(\mathbf r) + (\mathbf a \cdot \nabla )f(\mathbf r) + \frac{1}{2!}(\mathbf a \cdot \nabla)...
41
votes
5answers
17k 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. ...
46
votes
3answers
7k views

Generating a broken or snipped axis in ListPlot

I have two data sets, data1 and data2. For example: ...
42
votes
4answers
7k views

Fastest way to calculate matrix of pairwise distances

It is a very common problem that given a distance function $d(p_1,p_2)$ and a set of points pts, we need to construct a matrix ...
19
votes
2answers
5k views

How to make traditional output for derivatives

Hello again after some pause. i have a problem how to present partial derivatives in traditional form, not as Mathematica gave it to me in its notation. So I want to present this ...
104
votes
9answers
5k views

Functional style using lazy lists?

Let's say I want to answer the question "what are the first 400 palindromic prime numbers?" The first approach that comes to my mind from the set of languages that I know is to use some sort of lazy ...
74
votes
6answers
4k views

How to abort on any message generated?

Mathematica is a bit unusual as a programming language because it never stops on messages, regardless of whether the message is an error, a warning or just an informative message. It simply prints the ...
31
votes
2answers
4k views

Determining which rule NIntegrate selects automatically

I need to numerically integrate a highly oscillatory function over the semi-infinite domain $(0,\infty)$: $$\int_0^\infty \frac{\sin^2(x) \sin^2(1000 x)}{x^{5/2}}\mathrm dx$$ Since the Levin rule (...
43
votes
7answers
5k views

Extruding along a path

I'm trying to render a 3D image of a path by extruding a circular cross-section along the path, to create a "snake-like" path. Here is an image I found to illustrate: I can't seem to figure out if ...
24
votes
3answers
12k views

About the number format in ticks

I want to LogPlot a function, but I have the trouble in the number format in the ticks. For example, ...
52
votes
2answers
2k 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 ...
15
votes
2answers
5k views

Error entering equation in DSolve

I entered a command incorrectly as follows: DSolve[{y'[x]=y[x]},y[x],x] I am now experiencing: ...
5
votes
4answers
364 views

Expressions containing globally undefined symbols inside a function where they are defined

Consider the following code. f[a_,b_]:=x x=a+b; f[1,2] (* a + b *) From a certain viewpoint, one might expect it to return 3 ...
111
votes
3answers
5k views

Programmatic formatting for Mathematica code - possible?

It seems to be both an interesting programming challenge and a very useful practical application to have a Mathematica program which would allow one to pretty-print Mathematica code, so that it is ...
65
votes
7answers
4k views

Functions vs. patterns

Every time I define a new function, I wonder which construct I should use: true functions obtained by using Function, or rule-based syntax. For example, these are ...
48
votes
7answers
3k views

Character edge finding

The following line of code finds the edge of a character: ...
37
votes
6answers
4k views

How to splice together several instances of InterpolatingFunction?

I have a set of InterpolatingFunction returned by NDSolve which are valid over different (but overall continuous) domains. How ...
45
votes
1answer
2k views

Transferring a large amount of data in parallel calculations

Bug fixed in version 11.1 Functions like MemberQ, FreeQ, etc. no longer unpack. Yay! This question is inspired by one of @...
24
votes
6answers
4k views

Annoying display truncation of numerical results

I have a lot of data to inspect. An example of a number in my program is 123.189094 This gets displayed as 123.189 ...
596
votes
6answers
183k views

xkcd-style Plots

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 ...
68
votes
4answers
13k views

Placing a ContourPlot under a Plot3D

I would like to combine a 3-dimensional graph of a function with its 2-dimensional contour-plot underneath it in a professional way. But I have no idea how to start. I have a three of these I would ...
53
votes
9answers
3k views

Levels: how do they work?

I cannot understand how Mathematica manages levels, and so it's always a painful try-and-fail to use Flatten. Can someone please give me a very clear definition? ...
42
votes
5answers
11k views

ListPlot with each point a different color and a legend bar

I would like to generate a ListPlot with the color for each point in the plot corresponding to a particular value (not associated with the position in the plot). I'...
39
votes
2answers
3k views

Aligning plot axes in a graphics object

I need to align the y-axes in the plots below. I think I'm going to have to do some rasterizing and searching for vertical lines, then vary x and ...
47
votes
2answers
2k views

Why does Simplify ignore an assumption?

Here is the example: Simplify[x + y, x + y == a] Simplify[x + y, x + y == 5] Mathematica 9 output: x+y 5 I expect the ...
8
votes
2answers
2k views

A problem about function N

Toady,I have a problem about N,described as below: For example N[1/3, 5] (* ==> 0.33333*) and ...
18
votes
3answers
5k views

How do I convert an argument list to a sequence of arguments?

I think this is a basic question, but I am having difficulty finding the answer in the documentation. Thread is not what I am looking for, I think. Suppose that I ...
109
votes
1answer
2k views

Why are numeric division and subtraction not handled better in Mathematica?

There is something that has been troubling me for a while. At least through version 10.0 the performance of a / b and a - b is ...
60
votes
3answers
4k views

How can we make publication-quality PlotMarkers without version 10?

Suppose that for certain reasons we are not yet using Mathematica version 10, or we have a version with buggy PlotMarkers. It is well known that the default markers ...
39
votes
3answers
5k views

Avoiding white lines inside filled area in RegionPlot exported as PDF or PS

When doing a RegionPlotand then exporting (or saving from the front end) as PDF or EPS, there are small white lines in the filling of the region. Here's an example ...
36
votes
5answers
7k views

Clear complains that a subscripted variable is not a symbol or a string?

Here's a small listing where I've used EscqEsc to typeset θ in the notebook: ...
21
votes
4answers
9k views

Find all roots of an interpolating function (solution to a differential equation)

I'm trying to find all the roots of the solution to a differential equation. Using NSolve or Reduce I don't get the roots, so I'm using an iterative method which I found in physicsforums.com. This ...
38
votes
1answer
936 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 ...
23
votes
2answers
912 views

Where can I get detailed information on how the Plot command works?

The command Plot[x^2, {x, -3, 3}, PlotStyle -> Arrowheads[{-.025, .025}]] /.Line -> Arrow produces this output. What I don't understand is what ...
11
votes
4answers
5k views

Problem with ContourPlot

I tried these ...
7
votes
1answer
3k views

White regions in DensityPlot — is this a bug with ColorFunctionScaling?

Is this a bug with ColorFunctionScaling? When I try to supply my own ColorFunction Mathematica seems to partially ignore it, ...
145
votes
3answers
10k views

How to make use of Associations?

I have been curious about it for long. Now that Mathematica 10 arrives, I think it's time to ask the question: How the new Association data structure would be used ...
104
votes
6answers
11k views

Minimal effort method for integrating C++ functions into Mathematica

Update: While at the time of writing the question loading DLLs with .NET/Link seemed easier, now I always use LibraryLink, which I recommend to anyone with a similar problem! As of Mathematica 8, ...
70
votes
3answers
3k views

The clearest way to represent Mathematica's evaluation sequence

WReach has presented here a nice way to represent the Mathematica's evaluation sequence using OpenerView. It is much more clear way to go than using the standard <...
79
votes
1answer
2k views

Incompatible Changes since Mathematica Version 7?

There is documentation of the incompatible changes made to Mathematica with each major release: Incompatible Changes since Mathematica Version 1 Unfortunately that documentation simply stopped ...
41
votes
1answer
3k views

Why won't Parallelize speed up my code?

What reasons are there that can cause parallelized Mathematica code not to run with full performance?
50
votes
1answer
2k views

What are SparseArray Properties? How and when should they be used?

A strange undocumented form of SparseArray is increasingly used in answers on this site: ...

15 30 50 per page