Questions tagged [functions]

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

Filter by
Sorted by
Tagged with
242
votes
8answers
16k views

What are the use cases for different scoping constructs?

Mathematica includes three functions that I know of which can be used to effectively (if not actually) define a variable and give it a value within a local scope: ...
168
votes
8answers
20k views

List of compilable functions

Is there somewhere a list on the functions that Compile can compile, or the cases in which a particular function can be compiled that I haven't found? I'd be glad ...
192
votes
22answers
15k views

What are some useful, undocumented Mathematica functions?

There have already been some questions about some undocumented functionality in Mathematica. Such as (please add to these lists!) How can one find undocumented options or option values in Mathematica?...
50
votes
5answers
3k views

Enforcing correct variable bindings and avoiding renamings for conflicting variables in nested scoping constructs

Using global variables the following turns an "expression" into a Function: expr = 2 x; Function[x, Evaluate[expr]] Of course ...
105
votes
2answers
26k views

What is the difference between Reduce and Solve?

Solve and Reduce both can be used for solving equations. Just by working with them, I know there are some differences between ...
32
votes
2answers
3k views

Plot Option Precedence while combining Plots with Show[]

I like to build sophisticated plots by combining simpler ones with Show[]. Typically this involves setting non-default Plot-Options with the different Plot-Commands,...
80
votes
4answers
6k views

Using a PatternTest versus a Condition for pattern matching

My last question to the site resulted in several answers that involve using pattern matching in Mathematica, a feature I wasn't very familiar with at the time. I am currently reading Mathematica ...
38
votes
4answers
10k views

How to modify function argument?

Usually in programming languages, function arguments are normal local variables, which can be modified. Is this not true in Mathematica? ...
51
votes
2answers
7k views

Scan vs. Map vs. Apply

I cannot understand the difference between Apply, Scan, and Map. I have tried to play with ...
35
votes
7answers
9k views

Extracting the function from InterpolatingFunction object

I've used Interpolation[] to generate an InterpolatingFunction object from a list of integers. ...
5
votes
4answers
509 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 ...
58
votes
2answers
6k views

What is so special about Prime?

When we try to evaluate Prime on big numbers (e.g. 10^13) we encounter the following issue: ...
59
votes
2answers
3k 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: ...
45
votes
5answers
2k views

How can the behavior of InterpolationOrder->0 be controlled?

In ListPlot and Interpolation, the option InterpolationOrder->0 uses two different ...
29
votes
5answers
6k views

Plotting piecewise function with distinct colors in each section

I have a piecewise function that I would like to plot but I was wondering if it is possible that each part of the function that is plotted when its corresponding condition is true be plotted with a ...
14
votes
2answers
690 views

How can I make assignments persist across sessions?

Yesterday, I imported a large set of data into a Mathematica notebook and stored each imported list of numbers in a function. For example, I would map a list like ...
98
votes
4answers
3k views

What best practices or performance considerations are there for choosing between Cases, Position, Pick and Select?

Cases, Select,Pick and Position each have different ...
14
votes
5answers
10k 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)$. ...
57
votes
4answers
2k views

How to create expanding summary boxes like the ones displayed for InterpolatingFunction, NearestFunction, etc.?

The display forms for objects like ClassifierFunction are nice clickable summary boxes I like this, and now I'm trying to create my a custom version of this for my ...
44
votes
4answers
7k views

Implementing continuous phase/Arg function

In MATLAB there's a function called phase that is just like our Listable friend Arg, but ...
90
votes
4answers
5k views

Automatically generating a dependency graph of an arbitrary Mathematica function?

Has anyone written a function to pull the function dependencies of a function? That is, it would be nice to have a function that returns a list of function dependencies as a set of rules, terminating ...
41
votes
2answers
4k views

What are some common issues with fitting functions to data?

Mathematica has numerous functions designed to, or capable of, fitting known functions, and finding unknown functions to match data sets. What are some common issues that come with finding those fits?
47
votes
3answers
1k views

Why is the new PositionIndex horribly slow?

This issue has largely been mitigated in 10.0.1. New timings for the final test below are: ...
48
votes
1answer
989 views

What does Internal`InheritedBlock do?

What does the function Internal`InheritedBlock do? How is it different from the regular Block?
23
votes
1answer
921 views

Shorter syntax for Fold and FoldList?

I find it tedious to write out the following: a = {1, 2, 3, 4}; Fold[f, First @ a, Rest @ a] f[f[f[1, 2], 3], 4] It ...
38
votes
3answers
2k 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 ...
44
votes
5answers
2k views

Why is there no PositionFunction in Mathematica?

Too often I have seen the programs of inexperienced users greatly slowed by using Position in an iterative fashion, when far faster would have been to compute a ...
29
votes
2answers
1k views

Block attributes of Equal

I answered “Equating matrices (or higher order tensors) element-wise” with: ...
23
votes
8answers
2k views

Applying And to lists of Booleans

I'd like to take {True,True,False} and {True,False,False} and apply And to get ...
14
votes
6answers
4k views

Prevent Part[] from trying to extract parts of symbolic expressions

If you have a list, e.g. {1, 2, 3} then you can extract the $k$th part using Part (...
14
votes
2answers
5k 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. ...
26
votes
1answer
1k views

More Ticks::ticks errors in AbsoluteOptions in v10

Bug introduced in 7.0 or earlier, fixed in 13.0. While the specific bug affecting Plot described in AbsoluteOptions prints error messages in V10 has been fixed in ...
29
votes
2answers
17k views

Pass function or formula as function parameter

I can write either Integrate[x^2, {x,0,3}] or f[x_] = x^2 Integrate[f[x],{x,0,3}] and get the same computation. Suppose I ...
36
votes
3answers
1k views

DeleteDuplicatesBy is not performing as I'd hoped. Am I missing something?

Déjà vu: a new-in-v10 function should provide a better solution to an old problem, but my enthusiasm is curbed when I run timings. This time the function is ...
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: ...
40
votes
3answers
1k views

Is there a name for #1@#2&?

Why does the pure function # @ #2 & have no name? I'm asking because sometimes I find inelegant to write expressions like ...
48
votes
1answer
1k views

Is FullGraphics an abandoned function? Is there an alternative?

FullGraphics hasn't worked entirely for a long time and the situation appears to be getting worse instead of better. In Mathematica 10.0, 10.1 up to 11.3 a simple ...
7
votes
3answers
2k views

How to plot several functions without jumping? (multiple eigenvalues of a system as functions of 2 parameters)

I've been working on this research problem for months with some success by no global/proper solution to the problem. So I have square, Hermitian matrices of various sizes ($8,20,38$ dimensions) with ...
6
votes
2answers
2k views

Derivative of conjugate multivariate function

I have a problem with Mathematica, taking the derivative of the conjugate of some function. I know that a similar question has been posed before here, but the solution did not work for multivariate ...
7
votes
2answers
951 views

Position function not always returning an answer even with no apparent problems

I'm having some problems with Position. Sometimes it will give an empty list instead of the actual position of the element I am looking for when that element is ...
18
votes
4answers
2k views

Pure Functions with Lists as arguments

Assuming I have two function: example 1: add[{x_, y_, z_}] := x + y - z add[{1, 3, 5}] If use pure function,I know I can write it as : ...
20
votes
1answer
2k views

How do I create a triangulated surface from points?

I have a set of points in a nx3 matrix and I would like to convert them into a surface, so that I may calculate its surface area. The function ListSurfacePlot3D creates the surface how I want it. ...
7
votes
1answer
2k views

How Can I use Solve/Reduce Output

Suppose I want x and y to be rationals Solve[ x^2 + y^2 == 1, {x, y}, Rationals] I am ...
6
votes
2answers
654 views

Manipulating slots in a pure function

How does one manipulate the slot numbers in a pure function? Some trick with Evaluate or Hold? I'm aiming for something along ...
31
votes
3answers
2k views

Is there a "precedence table" for the canonical Sort ordering?

This answer in which I wrote about the Operator Precedence Table was unexpectedly popular. That got me thinking about similar things, and I am wondering: Does an "ordering table" exist for the ...
8
votes
4answers
2k views

Solve with v9 (issues with Subscript, Overscript, Superscript etc)

The way Solve works has changed in v9 ... in essence, to get the answers that one obtained under v8, one now often has to specify a lot more information about all ...
3
votes
2answers
2k views

Get leading series expansion term?

Given a function f[x], I would like to have a function leadingSeries that returns just the leading term in the series around <...
47
votes
3answers
79k views

How to tell Mathematica that certain variables are real/imaginary, integer-valued, etc

I'm trying to expedite some quantum mechanical calculations (expectation values etc.) by running them through Mathematica. When I say, for example, ...
30
votes
3answers
994 views

Parentheses in pure functions: # & vs. ( # &)

I've been using Mathematica for years, and over time I have developed the habit of using: Select[data, (# == 1 &)] instead of ...
39
votes
0answers
974 views

Performance problems in new Sequence functions

The new-in-10.1 Sequence* family of functions should provide newly optimized methods for handling sequence problems. Happily in some cases they do! For example ...

1
2 3 4 5
12