For questions on writing functions (pure or using Set/SetDelayed) for any purpose, including the features that may be incorporated in those functions, such as options, patterns and conditions.

learn more… | top users | synonyms

4
votes
1answer
127 views

Jackson Integral

Following an old post, I have tried to make a function that calculates the Jackson integral of $q$-calculus: ...
0
votes
0answers
60 views

Normal ordering in Mathematica

I want to create a function which normally orders a string of field operators. Consider the following: $$\langle0\vert\hat{a}(k_n) \cdots \hat{a}(k_2)\hat{a}(k_1)\hat{a}^\dagger(k_1)\hat{a}^\dagger(...
0
votes
1answer
42 views

Finding text files in a given path and applying a function to those files

I made a function called "SolveLinearSystem[]" that solves,as its name suggests, a linear system of any amount of variables. It takes the path of a text file as its only argument. The function then ...
0
votes
0answers
56 views

Problems with Tooltip

I an getting strange behavior with functions built using Tooltip. I create a function to display the position of data in a list ...
3
votes
2answers
123 views

Computing powers of the operator using symbolic computation

Suppose $t\in\mathbb{R_+}$ - some parameter, $V: \mathbb{R}\to\mathbb{R}$ - some function. I have an operator $S:f\mapsto S[f]$ that maps a function $f$ to a function $S[f]$: $$ S[f](x) = f(x+\sqrt{t})...
1
vote
1answer
70 views

Specifying Options when using Map abbreviated form (“/@”) [closed]

I want to make /@ with some option, Like PlotRange->All ...
4
votes
3answers
208 views

Recursive definition of nested functions

This is probably very easy, but I cannot figure out a way to define a function like: $$ g_h = ( 1 + f_1(1+f_2(1+f_3(.. (1 + f_h)))))$$
1
vote
0answers
52 views

A kind of function optimization problem [duplicate]

I have the following problem. Out of a calculation I got the four functions shown at the end of the post. These functions depends on many variables, qk, pk etc (all of them are actually scalar ...
1
vote
2answers
159 views

How do I get Series[] as a functional, rather than as an expression (i.e. to avoid the dummy variable)?

How can I write an equivalent to Series that doesn't require a dummy variable? Note that the series should be constructed before the evaluation point is supplied, ...
1
vote
1answer
40 views

How do I convert an expression that is a function of some variables into a functional?

If I have an arbitrary f[x, y, z], how do I convert it to f[#1, #2, #3] & without messing up scopes or causing scope leakage?...
5
votes
3answers
129 views

How to define a function whose parameter have a list with default-value

As we know,we can define a function with default-value like this: fun1[x_, n_: 1, a_: 2, b_: 3] := x + n + a + b In[6]:= fun1[4] Out[6]= 10 But in my ...
4
votes
3answers
92 views

Set absolute options for a function?

How can I set an absolute option for a user-defined function? I understand I can define options like this: ...
4
votes
2answers
181 views

How can I define the majority function?

I came across the majority function while falling into a Wikipedia link rabbit hole (I wish I could remember how I got there...) The function is defined for $n$ arguments and given by $$\mathrm{maj}(...
2
votes
2answers
81 views

Finding zero of nonlinear simultaneous equations [closed]

I'm trying to find the zero of nonlinear simultaneous equations defined in myfun1 and myfun2: ...
0
votes
0answers
31 views

Applying a function to the second element of a list [duplicate]

I'm trying to apply a simple function to the second element of a list: {#1, #2/5} &@{1, 2} But this returns an error message. ...
0
votes
1answer
30 views

Using the Function construct in a table with parameters [duplicate]

I'd like to define a table of functions like so Table[Function[{x,y},{x + k y,x - k y}] , {k,1,10}] My intention is to have the first function defined with k=1, ...
1
vote
1answer
48 views

Is there a way to make the Function construct accept a list as argument? [duplicate]

Is there a way to make the Function construct accept a list as argument ? Writing Function[{x,y},{x+y,x-y}] does not work, ...
3
votes
0answers
114 views

Obtaining a Previously Constructed Function as Desired Output

I was playing around with some Generalized Trigonometric Functions defined as follows; ...
1
vote
2answers
55 views

Importing data, then plotting ListPlot. What's the most efficient way to write a code?

It should be a boring question to ask for someone, but this is very basic need which I haven't resolved by myself. I know I can use MapThread and pure function to make it short and beautiful, but even ...
1
vote
1answer
53 views

Using the Nest function — Confusion on my output

I have the following code and output where the original function is $f(x,a) = a^2 - x^2$. ...
0
votes
1answer
50 views

Convert string to function with an argument

I am trying to build an expression by first writing it out as a string and then using ToExpression to convert it to an expression. However, I cannot figure out how to make expression recognize x as an ...
2
votes
0answers
50 views

First position of incremental series

I am still a beginner and maybe I want to do something too complicate! After 29 cycles I obtained the following events list: ...
1
vote
2answers
77 views

Problems using a function as an argument

I made a function: f[x_]:=x^2+1 and when i use it on, for example f[5], i get the answer 26. . But when i use it on: PollardRho[a_, f_] := Module[ {}, Return[f[a]] ] And when i write ...
8
votes
3answers
244 views

How to create a version of FixedPointList for asymptotically periodic functions?

I need to efficiently generate a bunch of bifurcation diagrams. A simple familiar example illustrates the efficiency problems I'm running into: ...
1
vote
0answers
49 views

NonLinearModelFit to a Function [closed]

I have a multiple dimension function that is fairly complicated. Instead of simply using Series to get a taylor series of the function, I would rather specify my ...
1
vote
0answers
78 views

Pattern for a function of say 2 variables [closed]

How can I specify a pattern for an expression f for which say f[x,y] returns a value, ie is defined as a function taking two ...
1
vote
1answer
177 views

How can I implement a moving standard deviation for a time series?

I imported the following dataset and converted it into a time series. ...
0
votes
1answer
46 views

Call user defined function from many notebooks [duplicate]

I wanted to ask a simple question. I am new to Mathematica, and I don`t find a way to call user defined functions just as I call Mathematica functions. I want to use my own defined functions, but ...
1
vote
1answer
85 views

Double arguments and place of the underscore

Could someone explain me of this bit of code below is correct: Is it possible to define a function with a second bracket, see below, i.e. f[x_][y_]? And what does ...
3
votes
2answers
257 views

Handling options in my function [duplicate]

It seems this should be easy, by I just can not figure out how. I'm making many very similar style plots, so I want to make a function with all the default options specified. Sometimes I need to tweak ...
7
votes
2answers
154 views

How to define a complicated function inside the body of Compile?

I want to compile a function in a way to keep its memory footprint down. In the example below, I am trying to compile a function f that makes three calls to ...
1
vote
2answers
85 views

What's the easiest way to remove overall factors from polynomials?

I have code that outputs polynomials (in #1) such as the ones below (note that the trailing Function character ...
8
votes
6answers
279 views

Combinations of multiple matching patterns

I wonder if there is any nice way to combine DownValues (or any other suitable rule-/pattern-/function -based Mathematica construct) when multiple patterns match an expression. Let me explain what I ...
9
votes
1answer
148 views

Maximizing a recursive functional equation

I would like to maximize a recursive functional equation but I am struggling with setting up the problem correctly. The equation I am interested in captures the nature of a decision process over time ...
0
votes
1answer
51 views

Simple grouping equations [closed]

I'm new in the Mathematica world. A very basic question. I have been using the command Eliminate on a set of equations as follow: ...
4
votes
1answer
137 views

Are these two functions equivalent?

I checked several cases and saw that two functions are equivalent in these samples. However, are the two equivalent in all cases? Is there a way to check that? Explicit function: ...
1
vote
2answers
91 views

Evaluating While Loops inside Modules [duplicate]

I am trying to compute some objects inside while loops within modules, but I keep getting the following error: ...
1
vote
1answer
52 views

Construct all possible sets of pairs [duplicate]

I am looking for a nice way of constructing all possible pairings of a given list. Currently I am using the brute force approach of sieving the 2-partitions of all permutations. ...
3
votes
1answer
125 views

The basic primitive recursive functions

How can the basic primitive recursive functions be expressed in the Wolfram Language? Apparently here's an example for primitive recursion: ...
0
votes
1answer
48 views

How to define InterpolatingFunction on a variable set of points?

I would like to define an InterpolatingFunction to which data points are transferred as a parameter, e.g.: ...
4
votes
2answers
57 views

Is it possible to match a sequence with multiple heads without using Condition

Suppose I have: expr = Times[2, a[x,r], a[y,1], c[z,0,0], d[w,m]]; If I want to match a sequence of expressions with the same head ...
4
votes
2answers
162 views

Subset-type function construction

This is probably a very straightforward thing I am missing, and probably also a duplicate(!), but I can't for the life of me think how to do this cleaner. I want to achieve what ...
4
votes
1answer
92 views

Pertubation series of given equations

I would like to define a function that does the following. If I have an equation, for example: $$f(x)+[1-f^2(x)]+f^{\prime\prime}(x)+f(x)\ f^\prime(x)=0$$ and I am given a value for $f$ to expand ...
0
votes
0answers
77 views

How to change the built-in function? [duplicate]

As you can see,the original Differences will get {} when your parameter is a list with one element just. Differences /@ {{1, 2, ...
4
votes
2answers
108 views

Finding the smallest starting number producing a Collatz sequence of length 125 which ends with a value > 4

I'm supposed to do a Mathematica function that selects the smallest number not less or equal to 4 after 125 iterations. I am not good at coding, so some help/advice would be awesome. My code so far. ...
3
votes
2answers
51 views

How to add Optional Sequence

Note: This question could be duplicate but I couldn't find any so far. It is know that Optional (:) can be use to represent expression if omitted. ...
0
votes
1answer
52 views

Cumulative function definition and plotting [closed]

I'm quite new to Mathematica. I have an issue defining cumulatively a function. Let's say I have a waveform f[t] , and I want to create a function with many copies ...