Questions tagged [functions]

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

Filter by
Sorted by
Tagged with
26
votes
1answer
4k views

Error checking and trapping techniques with Throw and Catch

Mathematica provides several mechanisms for checking arguments and trapping errors in a function definition. Typical methods are : Definitions with argument patterns, definitions with ...
25
votes
5answers
851 views

Partitioning a list when the cumulative sum exceeds 1

I have a long list of say 1 million Uniform(0,1) random numbers, such as: dat = {0.71, 0.685, 0.16, 0.82, 0.73, 0.44, 0.89, 0.02, 0.47, 0.65} I want to ...
25
votes
3answers
5k views

Difference between @ and @@

I am confused by the commands @ and @@. From the documentation, I learnt that @@ is the ...
25
votes
2answers
17k views

Is there an equivalent to MATLAB's linspace? [duplicate]

Does Mathematica have an equivalent to Matlab's linspace? I want to make a list with "start", "stop" and "number of points". What is the neatest way of doing this?
24
votes
2answers
566 views

Why doesn't a Composition[] hold its arguments and what can be done about it?

Now that Composition (also RightComposition) has shorthand syntax I am more inclined to use it, however what I feel should be ...
24
votes
1answer
1k views

More Ticks::ticks errors in AbsoluteOptions in v10

Bug introduced in 7.0 or earlier and persisting through 11.3 While the specific bug affecting Plot described in AbsoluteOptions prints error messages in V10 has ...
24
votes
1answer
623 views

Why does list assignment with a packed array result in unpacked values?

Bug introduced in 5.2 or earlier and fixed in 10.1.0 This is another question on the design choices in Mathematica. I understand that without direct reply from the developers it may not be possible ...
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 ...
23
votes
3answers
593 views

Is there a bug in Pick?

I wanted to use the Pick function with a condition. But there seems to be an issue here. Take a look at this: ...
23
votes
1answer
895 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 ...
23
votes
2answers
295 views

What's going on with performance of Tally here?

Observe: ...
23
votes
1answer
416 views

What is PointForm?

I stumbled across a function called PointForm but the only documentation I can find is the pop-up line offered by autocomplete, which contains the same information ...
22
votes
1answer
367 views

What does “EquationalLogic`FindCounterexample[]” do?

I found the undocumented EquationalLogic`FindCounterexample[] by browsing the lists of available symbols, but I have no clue about its purpose. The name is ...
21
votes
3answers
972 views

Can someone explain this snippet: (#[#] &)[#[#][#] &]

A friend showed me this snippet of code today: (#[#] &)[#[#][#] &] I can sort of see that we're constructing an anonymous function that takes a function ...
21
votes
5answers
13k views

How to find the domain and range of a function with Mathematica?

I'm studying calculus and in some exercises I am asked to find the domain and range of a function. Does Mathematica have already a built-in function for this? I can imagine some ways of doing so, ...
21
votes
5answers
719 views

Distributing function arguments with function compositions. How to compute $(f + g^2)(x) = f(x) + g(x)^2$?

Suppose I have two functions f and g. To compute $f + g$ evaluated at a point $x$, I know that one can use ...
21
votes
2answers
496 views

Where is the old option TraceInternal->True?

Already at least in version 2 (I think), the function Solve calls the function Roots. At that time, I had a rather dirty trick, that still works, to verify this: ...
21
votes
1answer
672 views

Why does the documentation call functions “pure”?

Clearly, functions in mathematica are not pure functions according to the definition on Wikipedia (no side effects - basically implementabe with table lookups): ...
20
votes
5answers
2k views

Moving maximum function?

How can I construct a moving maximum function? For example, if I have a list of 12 values: { 5, 6, 9, 3, 2, 6, 7, 8, 1, 1, 4, 7 } and I want to maximize over 3 ...
20
votes
6answers
6k views

How to completely delete the head of a function expression

Is there any way to completely remove the head of an expression function? For example, how would I remove the head Cos from ...
20
votes
4answers
2k views

Accessing list elements by name

First, a bit of a long introduction to my problem: I only have a few weeks of Mathematica experience. I am creating a mathematica application that calculates some material properties of steel based ...
20
votes
2answers
699 views

Using several anonymous functions mixed together

This works: list // BarChart[#[[2]], ChartLabels -> DateString @@@ #[[1]], ChartStyle -> "Pastel"] & This doesn't: ...
20
votes
4answers
714 views

How to keep some of the results of the NestList

I'm using some iterative arithmetics to calculate wave propagation with the help of NestList. I have to use a small step size for iteration to guarantee the accuracy, which lead to too much data (e.g, ...
20
votes
2answers
1k views

Nest , Fold … is there an extension for more than 2 arguments?

Fold is an extension of Nest for 2 arguments. How does one extend this concept to multiple arguments. Here is a trivial example: ...
20
votes
2answers
1k views

Function with custom Options and modified Options for built-in Symbols

I couldn't find a more descriptive title, but I guess an example will explain my problem. I set up some customized Grid function including some additional ...
20
votes
2answers
430 views

How does Rescale[] handle infinities?

Rescale appears to be a simple function. It just does a simple linear $y = a x + b$ type rescaling of the values: ...
20
votes
2answers
826 views

How do I override options with my own defaults?

I'm calling a function f from within a function g and would like to pass any valid options for ...
20
votes
1answer
1k 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. ...
20
votes
1answer
285 views

How to get Cases to wrap results in an arbitrary head?

A number of functions provide for results to be wrapped in an arbitrary head. This is very important in cases where the results should not be evaluated. Take Level...
19
votes
2answers
5k views

Sum or Product with Exclusions

Is there a built-in feature for handling things like: $$\sum_{\substack{i=0\\i\ne j}}^n\frac{a-a_i}{a_i-a_j}$$ and $$\prod_{\substack{i=0\\i\ne j}}^n\frac{a-a_i}{a_i-a_j}$$ or should I work out some ...
19
votes
1answer
380 views

What is the difference between defining a function and specifying the type of argument, versus applying a test to that argument?

Say I want to create a function that evaluates differently based on what type of argument is given. I've found two ways of doing this, ...
19
votes
1answer
670 views

Why won't SparseArray let me store values with the head List?

When you attempt to define a SparseArray with elements that have the head List it complains: ...
19
votes
1answer
658 views

DumpSave 10.2 style from 10.3

Szabolcs has asked WRI support about mx files, in particular: Can we expect that MX files written by Mathematica 10.0.0 will be readable by future point released such as 10.0.1 or 10.0.2? ...
19
votes
1answer
283 views

HistogramList is much Slower in 10.2 vs 10.1

While I was running a code I wrote using version 10.1, I noticed that in version 10.2 the running time of the same code was more than twice as long. After some digging, I figured out the culprit is <...
19
votes
1answer
284 views

Undocumented fourth parameter of Collect; how long has it been there?

While tinkering with How to get a list of monomials of a polynomial without coefficients? on a whim I tried a fourth argument in Collect and found: ...
18
votes
6answers
4k views

Max of a table/list with indeterminate values

Suppose I have a Table: tab = {1., 2., 3., Indeterminate} When I type Max[tab] I get ...
18
votes
3answers
1k views

What functions work in which version of Mathematica

Is there any good documentation on which version will work (remained the same) in which version of Mathematica? Or at least an overview of when functions were introduced? In this instance for example ...
18
votes
3answers
4k views

Fitting ellipse to 5 given points on the plane

Five points are required to define a unique ellipse. An ellipse has five degrees of freedom: the $x$ and $y$ coordinates of each focus, and the sum of the distance from each focus to a point on the ...
18
votes
6answers
1k views

How can I evaluate only a single step of a recursive function?

Let's say have a simple recursive function for the Fibonacci sequence f[0] := 1 f[1] := 1 f[n_] := f[n - 1] + f[n - 2] but I want to see how it will expand in a ...
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 : ...
18
votes
3answers
21k views

Map w/ multiple arguments [duplicate]

Possible Duplicate: How do I use Map for a function with two arguments? If I have a function: F[x_,y_,z_]:=x*y*z and I want to call it with several ...
18
votes
3answers
4k views

Write C/C++ programs calling Mathematica functions

I need to write a C/C++ program and call some functions in Mathematica especially those like Solve or NDSolve. The problem is ...
18
votes
6answers
386 views

Prevent Plus from threading

This is probably a very simple question, but I couldn't find a duplicate. As everybody knows, {x, y} + v gives {x + v, y + v}. ...
18
votes
3answers
3k views

Moving the location of the branch cut in Mathematica

According to the documentation, Mathematica chooses the branch cut for $\log(z)$ to lie along the negative real axis. It it possible to change this so that it lies along the positive axis or elsewhere ...
18
votes
2answers
3k views

Is there a built-in function which detects singularities in a function?

Given a function f[x] and a region M in the complex x-plane, how can I find singularities of f in this region, i.e., issue a ...
18
votes
0answers
245 views

V10's TypeSystem - what are these function useful for? [closed]

The symbols in the TypeSystem` context are clearly used for working with Datasets, but they seem powerful. I was hoping that someone could help explain how they work and is they are useful for ...
17
votes
5answers
23k views

Calling Correct Function for Plotting DiracDelta

I am wondering what is the correct function in Mathematica to plot the true impulse function, better known as the DiracDelta[] function. When using this inside of a ...
17
votes
6answers
2k views

Will Version 9 functions all work in Version 10?

Having developed a substantial code base in Mathematica 9, leads me to ask these important questions prior to downloading and installing Mathematica 10. Will any Mathematica functions from the ...
17
votes
5answers
567 views

Partitioning a list of numbers the Mathematica way

I have two sorted lists, one list will be called the "fences" and the other the "values" Fences could be: $\{1, 5, 9, 14\}$ Values could be $\{-1, 1, 3, 4, 6, 9, 10, 13, 14, 15\}$ I want to ...
17
votes
4answers
5k views

Function to subdivide interval into n evenly-spaced points

[This post needs better tags than I could come up with. Edits to the tags would be particularly welcome.] I realize that it is trivial to define a function that takes an interval (i.e. two endpoints,...

1
2
3 4 5
57