Questions tagged [functions]

Questions about the use of built-in Mathematica functions, including pure functions.

Filter by
Sorted by
Tagged with
17
votes
4answers
2k views

How to make a function with its own options as well as passing options to other functions [duplicate]

I have a function with many of its own options, but I would also like to pass options to subfunctions using the FilterRules function. Here's a simple example: <...
17
votes
2answers
843 views

Creating a NearestFunction that returns an index

I use Nearest repeatedly for large data sets. For example pts = RandomReal[{-1, 1}, {1000, 3}]; Nearest[pts, {0, 0, 0}] I ...
17
votes
1answer
2k views

Get the name of a symbol passed to a function

I'm trying to get the name of a symbol passed to a function with this: f[x_] := {SymbolName[x], x} SetAttributes[f, HoldFirst] x = 5; f[x] But ...
17
votes
8answers
1k views

Enumerating tuples from a larger space such that all pairs of values are present at least once

I am trying to write a function that will accept a list of N lists and returns a list of N-tuples that represent all pairs of values from the original N lists at least once. To illustrate with an ...
17
votes
2answers
2k views

Why do certain values in ArcSin not fully evaluate?

This is a continuation of: Why do certain fractional values in TriangleWave not evaluate? The analysis by R.M and rasher revealed that problem to reduce to the behavior of: ...
17
votes
1answer
132 views

What is the potential usage of ReplaceAllUnheld in Developer Utilities Package?

There is a function ReplaceAllUnheld metioned in the doc Developer/ref/ReplaceAllUnheld. I am curious about what is the ...
17
votes
1answer
468 views

GeoGraphics: problem with GeoPosition in shifted projections

Bug introduced in 10.0.0 and fixed in 11.0.0 A remark about the answer: My work around is only nice for simple cases with points. More general should include proper polygons splitting on antimeridian....
17
votes
1answer
537 views

What Method options does FindInstance accept?

While answering Trouble getting FindInstance to return multiple results for certain constraints it became clear that for this problem FindInstance would be better ...
16
votes
6answers
6k views

Counting negative values in list

I would like to count the negative values of a list. My approach was Count[data, -_] which doesn't work. How can I tell Mathematica to count all numbers with ...
16
votes
6answers
739 views

Comparing the last output of a nested function with all the previous ones

my main question is how I can compare the last output of a nested function with all the previous ones and stop iterating when I find a repeating value. (I have 2 other questions but I think they are ...
16
votes
2answers
300 views

A bug in Commonest in version 10

Bug introduced in 10.0.0 and fixed in 10.0.2 m_goldberg demonstrated that in Mathematica 10 Commonest does not behave as the documentation indicates that it will. ...
16
votes
4answers
915 views

Is it possible to get the order of inputs when “overloading” an orderless function?

When working with symbolic matrix operations or other objects which don't have commutative multiplication, it would be nice to not have to constantly switch out times for ...
16
votes
2answers
376 views

Improving Performance of an XY Monte Carlo

I normally write my Monte Carlo codes in Fortran for speed, but I was doing some quick and dirty work and wrote one in Mathematica for the XY model on a square lattice (see Kosterlitz-Thouless ...
16
votes
1answer
266 views

Major slowdown when using a ColorFunction with more than one named scheme

Bug introduced in V10.1 or earlier and persists through 11.2 Earlier Kuba noted a major slowdown with code Simon Woods posted. Here is a simplified example. First a color function using two ...
16
votes
1answer
188 views

How can I view the minimal required arguments of a Wolfram Language function?

This question might be a bit of an overstretch, or really obvious, but I haven't been able to find an answer yet. Is there a way to automatically view the minimum required arguments for a WL function?...
16
votes
4answers
2k views

Big-Oh Notation

Is there a way to have Mathematica understand Big-Oh notation? For example, I want something like: MinBigOh[...] where ...
16
votes
2answers
443 views

What has changed in the Template system in 10.3?

Bug introduced in 10.3 and fixed in 11.0.0 There are couple of issues that are breaking my code after upgrading to 10.3. I wasn't able to narrow all of them down but this is what I've found. ...
16
votes
1answer
487 views

Better Autocomplete for the Front-End

I wonder if it is possible to improve the front-end's autocomplete capability. Compared with some other more sophisticated editors/IDEs, such as eclipse, Mathematica's front-end does not provide a ...
16
votes
1answer
214 views

Is it better to completely forget about the existence of PowersRepresentations?

I noticed that in several cases the performance of PowersRepresentations is hugely worse than that of IntegerPartitions. (Mma 10....
16
votes
1answer
475 views

How is the mysterious Raw function used?

I have never seen an example use for the mysterious Raw function: Raw[h, "hexstring"] constructs a raw data object with head h, and with contents ...
16
votes
1answer
543 views

Is everything in Mathematica ultimately stored as a rule?

My current understanding about Mathematica is that everything, at the lowest level, ends up as replacement rules. First question: is this true? Second question: does Mathematica "gloss over" these ...
15
votes
8answers
533 views

Is it possible to use RandomChoice to choose without other choices being evaluated?

I'm trying to do this: i1 = 1; i2 = 1; RandomChoice[{ (i1 = i1 + 1), (i1 = i1 - 1), (i2 = i1 + 1), (i2 = i2 - 1)}] In order to chose randomly which ...
15
votes
6answers
2k views

Building a continued fraction

I've completed a problem that involves approximating $e$ by a continued fraction: $$\frac{N_1}{D_1+\frac{N_2}{D_2+\frac{N_3}{\ddots+\frac{N_k}{D_k}}}}$$ with the $N_i$ being the list ...
15
votes
6answers
749 views

Reshaping associations, generalization of GroupBy

Let's say we have a set a\of associations: ...
15
votes
4answers
3k views

How do I plot Thomae's function in Mathematica?

I wanted to plot this function $$f(x) =\begin{cases} 1 & \text{if } x= 0 \\ \tfrac1{q} & \text{if } x = \tfrac{p}{q}\\ 0 & \text{if } x \in \mathbb{R}-\mathbb{Q} \...
15
votes
4answers
1k views

How to replace the first occurence in an expression instead of replacing all?

Is there a function that replaces the first occurence of the expression instead of replacing all? For example, if I have HoldForm[x + 2 + 4 + x] /. x -> 4, is ...
15
votes
2answers
3k views

NestList on a function of several arguments

I'd like to know if it is possible to use NestList on a regular function of several arguments, such as: ...
15
votes
2answers
530 views

a caveat in `Iconize`

We got this nice Iconize function to shrink code in notebook from version 11.3. But, I noticed a caveat in reverting an Iconize-...
15
votes
4answers
1k views

How to check the style and number of arguments like the built-in functions?

Given that I have a function sqrt[x] that I must check the style and number of argument x. I can do like this: ...
15
votes
3answers
936 views

Which function names have been re-purposed in Mathematica after being deprecated?

I have just learned about the new function Splice from this answer. It turns out that this function used to have a completely different usage! (See below.) To me, ...
15
votes
3answers
451 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 ...
15
votes
2answers
6k views

Is there an $n^{\text{th}}$ root function in Mathematica?

Is there a way to find $\sqrt[n]{x}$ with Mathematica beside of x^(1/n) as this is something different, because this is not always the same $$(-1)^{\frac{2}{4}}=i \...
15
votes
2answers
983 views

Fitting a curve to an image object: not a superellipse, not an egg curve.. what else?

I'm facing the problem of quantifying the morphology of objects with such a shape (nannoconids... they are fossils). One of the final goals is to produce a solid of revolution and compute volume/...
15
votes
1answer
414 views

Is there a summary of answers Head[] can give?

Sometimes you need to check for the type of an expression. You use Head[data] to get answers. Some data: ...
15
votes
2answers
2k views

Converting ConditionalExpression to Piecewise

I have Solve[] return a list like ...
15
votes
1answer
2k views

user defined functions, how to save them for future use?

I need certain user defined functions over and over. I was wondering how can I define and where and how to save them such that each time I start a notebook, these functions are available and need not ...
15
votes
1answer
653 views

Why is an Identity function needed?

Today I came across the function Identity[x] in Mathematica (documentation). The example given in the documentation uses it in ...
15
votes
1answer
625 views

Why is this evaluation halved when adding units?

Bug introduced in 9.0 or earlier and persisting through 11.2 or later Why does this strange behavior occur when dealing with units and quantities? ...
15
votes
1answer
309 views

Why do big-O terms disappear in definite integrals since Mathematica 9?

In Mathematica 8, when I computed the following input: Integrate[Series[Cos[x], {x, 0, 2}], {x, 0, a}] Mathematica returned an expression that had a O[a^4] in ...
14
votes
5answers
9k views

How to plot periodic function's graphic?

How to plot periodic function's graphic? For example, $f(t) = t$ when $-5<t<5$ and $f(t+10) = f(t)$. ...
14
votes
5answers
9k views

Make a differentiable smooth sawtooth waveform

So, I am trying to understand the effect of sawtooth waveform on a mechanical system model. For example, a system of a plate and a box on it. And then we try to oscillate the plate. In order to do ...
14
votes
7answers
442 views

Get the first element after the first sequence of length N of consecutively increasing values

I'm looking for an efficient way of extracting the first element after the first sequence of N consecutive elements in which the values are increasing. If these are the data of a toy example: ...
14
votes
4answers
468 views

Using With to scope over pure functions

Consider this example: given an option for a function func as "x" :> (a&), how can one assign different values to ...
14
votes
5answers
2k views

What is my problem with MeshFunction?

I want plot the max value in a sine plot. We can use the following code ...
14
votes
4answers
1k views

How to “ignore” an element of Map or MapIndexed

Say I have some function that I'm applying every element in a list to... if that element matches some criteria: ...
14
votes
2answers
607 views

How does FunctionDomain work?

FunctionDomain[(x^2-x-2)/(x^2+x-6),x] gives x < -3 || -3 < x < 2 || x > 2. However, when I factor the ...
14
votes
2answers
4k views

Finding all partitions of a set

I'm looking for straightforward way to find all the partitions of a set. IntegerPartitions seems to provide a useful start. But then things get a bit complicated. ...
14
votes
2answers
397 views

How to build a list of elements satisfying a certain property without building a list of all elements first?

Is there a way to directly build a list of elements that satisfy a certain property? More precisely, I am looking for a function IncludeIf (this is a placeholder ...
14
votes
4answers
3k views

Refering to global variables inside modules

How do I refer to global variables inside modules if the same name is used for a local one? In code, I want that ...
14
votes
1answer
261 views

What to expect from Interpreter[“Expression”]?

Sometimes it works ok Interpreter["Expression"]["1"] 1 sometimes not: Interpreter["Expression"]["Graphics[{}]"] Why ...

1 2
3
4 5
57