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

learn more… | top users | synonyms

10
votes
2answers
473 views

How to test if optional argument has been given?

I understand that the last call (f[1]) returns True because arg does not exist and thus ...
3
votes
7answers
839 views

Defining an integer-valued function on an integer domain

This should be an easy question! I want to define a function with domain = the 12 integers {1,12}, with the values f[1]=31, ...
4
votes
3answers
324 views

How to cancel floating point factors?

I am currently having problems with some floating points. I have a function, which gives as an intermediate result (for example) ...
9
votes
3answers
372 views

Problem when defining variable in Mathematica

I'm trying to run this: domain := {n, 0, 10}; Plot[n, domain] but it doesn't work. Instead, it generates the message ...
15
votes
6answers
2k 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 ...
9
votes
3answers
618 views

Inverting a function in a certain region

InverseFunction works well for globally invertible functions, like f = 2*# + 2 &; InverseFunction[f] ...
12
votes
2answers
1k views

How do I find the elements in a list that return the highest value for a function?

Suppose we have a list of values and a function f. I want to find which of the elements maximizes the return value of the function in Mathematica. Let call the ...
7
votes
2answers
2k views

Series of piecewise functions

Let $f_{0}(x):[0,1]\to[0,1]$ be defined by $$f_{0}(x):=\begin{cases} 3x, & \text{if } x\in [0,\frac{1}{3}] \\ \\ -3x+2, & \text{if } x\in (\frac{1}{3}, \frac{2}{3}] \\ \\ 3x+2, & ...
15
votes
3answers
646 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 ...
3
votes
1answer
2k views

Function that takes another function inside

Looking at this QA, I'm trying the following - 2 functions (r in vector format) using Theta { A, 2 } functions (sorry for the inconsistent names...). ...
17
votes
3answers
2k 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 ...
7
votes
3answers
338 views

Making sure that Timing[] isn't thrown off by caching

In playing with and comparing the various answers to my question here, I tried applying Timing[] to see how fast things ran, but it seemed that some of the answers ...
77
votes
8answers
6k 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 ...
14
votes
5answers
2k views

sprintf() or close equivalent, or re-implementation?

Is there a sprintf() command (some command that takes a printf-style format string and a list of values to insert into the ...
26
votes
5answers
1k views

Are there “All” and “Any” functions in Mathematica?

In Python, there is a function all which returns true if all of its arguments are true, and any which returns true if at least ...
10
votes
2answers
646 views

How to add an interpolating point to InterpolatingFunction?

Suppose I have an InterpolatingFunction object defined on $[\epsilon,1]$; let's call it f. What is the best way to construct a ...
14
votes
1answer
1k 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 ...
13
votes
1answer
14k views

How to express trigonometric equation in terms of of given trigonometric function?

How can I express a trigonometric equation / identity in terms of a given trigonometric function? using following trigonometric identities ...
10
votes
9answers
545 views

How to find range in which a number falls, from given list of numbers?

How can one find the range in which a number falls, from given list of numbers? ...
7
votes
2answers
280 views

What's the purpose of the Unique function?

As the title says: What's the purpose of Unique? I understand that it generates some unique symbol, but when and for what is it to be used? Are there applications ...
59
votes
2answers
2k views

Flatten command: matrix as second argument

One thing I could never wrap my head around is how Flatten works when provided with a matrix as the second argument, and the Mathematica help isn't particularly ...
12
votes
1answer
215 views

Choosing among different function definitions without sacrificing speed

I'm working on some code that numerically integrates a function, let's call it G, which calls another function, F, that can be ...
60
votes
3answers
2k 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 ...