Questions tagged [functions]

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

This tag is for questions about the use and application of built-in Mathematica functions. This includes the use of pure functions (# & constructs, see Function).

Questions on how to construct new functions should use the tag. Questions about the argument specification, order and syntax of built-in functions should use the tag. Questions about using pure functions and the functional programming style should use the tag . Special mathematical functions (like Gamma, BesselJ, etc.) should use the tag .

Do not use this tags to ask questions about (the properties of) mathematical functions. For such questions, use , or a similar applicable tag.

Useful links

Example questions

3770 questions
20
votes
2 answers

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: FoldList[#1 (1 + #2) &, 1000, {.01, .02, .03}] Say I want do something…
RobK
  • 417
  • 2
  • 7
16
votes
6 answers

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 so simple that they do not deserve a separate…
Jane T.
  • 495
  • 4
  • 8
16
votes
2 answers

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 \neq 1= \sqrt[4]{(-1)^2}$$ In the help I only found Sqrt[x] which is the squareroot…
Dominic Michaelis
  • 889
  • 1
  • 7
  • 18
16
votes
1 answer

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...). ihat = {1, 0, 0} jhat = {0, 1, 0} khat = {0, 0, 1} ThetaA[t_] := 0.2 Pi Cos[50 t]; Theta2[t_] :=…
IsaacS
  • 583
  • 1
  • 4
  • 14
15
votes
2 answers

Can we explain why using `Nothing` twice on a list does not operate twice?

Below I generate a list of numbers between 1 and 15. I then set the value at position 10 to Nothing and as expected the value at position 10 is changed. This is as expected. In[1]:= b = Range[15] b[[10]] = Nothing; b b[[10]] Out[1]= {1, 2, 3, 4,…
Hugh
  • 16,387
  • 3
  • 31
  • 83
15
votes
1 answer

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: data = {7, 1.4, Red, "hp", hps}; Head /@ data (*{Integer, Real, RGBColor, String, Symbol}*) Is there summary of what kind of answers Head[]…
12
votes
5 answers

How to prevent function from passing values to slot

For the following example: {#, #} & /@ {1, 2} I am trying to find a method to hold one of the slots (or both ) so that the function do not pass the values to the slot I want to protect. for example I want to get something like this: {{1, #}, {2,…
Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78
12
votes
2 answers

Growth of functions

Does somebody know if Mathematica can be used to calculate the growth of functions, that is in Big O, Theta, and Omega and find proper $n_{0}$ and $c_{1}$, $c_{2}$ respectively?
JanosAudron
  • 223
  • 1
  • 4
11
votes
2 answers

Tally repeated evaluation of function

How can I tally the result of repeated evaluation of a function? n=100000; f[]:=RandomInteger[{1, 4}] Tally@Table[f[], {n}] When n is really big this needs an unnecessary amount of memory, how do I get rid of the Table without slowing it down…
ssch
  • 16,590
  • 2
  • 53
  • 88
11
votes
4 answers

Replacing functions

Given an expression expresion in terms of a function f and given another function g, how could I write a Module that replaces the function f by the function g in the expresion expresion and returns it? An example: MyFunction[expresion_, f_, g_] :=…
José D.
  • 1,135
  • 10
  • 23
10
votes
4 answers

How to find the domain and range of an implicit function?

For example, we have this curve: $$x^2 + y^2 = 1$$ Is there a function in Mathematica for finding out that the ranges for $x$ and $y$ are both $[-1, 1]$? What about implicit functions of more than $2$ variables? e.g. $$x^2 + y^2 + z = 1$$
qed
  • 275
  • 2
  • 7
10
votes
1 answer

Naming arguments in Wolfram functions?

Sometimes you have functions with very long argument lists: f[a_, b_, c_, d_, e_] := c so is there a way to "name" these arguments (order insensitive) so that users can know what they're getting more easily? In pseudo-code: f[c = "what I'm…
George
  • 3,145
  • 7
  • 21
10
votes
4 answers

How do I apply something like the double slash notation but not at the end of line?

f[x_] = x^2; Scan[Print[f[#]] &, {1, 2, 3}] I want to do something like this, but I don't want to type so many brackets. I'd like to have something like f[x_] = x^2; Scan[f[#] //Print &, {1, 2, 3}] But this doesn't work. What's the correct…
seilgu
  • 497
  • 2
  • 7
9
votes
1 answer

Apply a Function Pairwise

I'm new to Mathematica I'd like to apply Mean pairwise to a list to achieve the following. badSource = {{0, 0}, {1, 1}, {2, 0}, {3, 1}, {4, 0}}; badInterpolation = {{.5, .5}, {1.5, .5}, {2.5, .5}, {3.5, .5}}; ListLinePlot[{badSource,…
schmijos
  • 265
  • 3
  • 6
9
votes
3 answers

Passing a function as an argument of another function

Possible Duplicate: Pass function or formula as function parameter I am trying to implement a simple Plot[]-like function, with the same synopsis; my first (and unique so far) try would be something along these lines: MyPlot[f_, {var_, xmin_,…
zakk
  • 978
  • 1
  • 7
  • 17
1
2 3
30 31