# Questions tagged [function-construction]

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.

1,866 questions
Filter by
Sorted by
Tagged with
27 views

### Passing input arguments to a function

I want to pass input arguments to a function In python I do, def solution3d(a, b, c, d): I looked at the documentation here https://reference.wolfram.com/language/...
36 views
+100

### What are some ways to overload Min in order for it to work with user defined expressions?

I have defined size to work with discrete size labels: ...
37 views

### Defined function keeps the variable

I'm a beginner at Mathematica, and I have a problem finding the roots of a function for a specific variable (using Jens' findAllRoots function). Due to the nature of my problem, I need to compute ...
64 views
+100

### Better way to rename arguments to a functional form so that duplicate arguments are sequentially enumerated

I need to modify expressions that such as f[w, w, a, y, x, a, x, a] into f[w1, w2, a1, y, x1, a2, x2, a3]. In short, I have ...
53 views

### Normalized functions

I'm looking for a smart way to define normalized functions. I usually write f[x_] := f[x] = A Sin[x]/x; Then I integrate the function ...
97 views

### How to define some functions automatically?

I want to use Gauss-Seidel iteration to solve this problem. $$\left\{\begin{array}{l} 8 x_{1}-3 x_{2}+2 x_{3}=20 \\ 4 x_{1}+11 x_{2}-x_{3}=33 \\ 6 x_{1}+3 x_{2}+12 x_{3}=36 \end{array}\right.$$ ...
74 views

### How can I fix my Simpson's rule integration code?

I was tasked with writing a function on Mathematica similar to NIntegrate, but that uses the Composite Simpson's Rule as its method for doing the calculation. The ...
87 views

### How to find formula from a table?

I recently started using mathematica for simple tasks like simplifying etc. First of all let me say if this breaks any rules I apologize since I'm a novice in using this and I'll remove the question. ...
49 views

### Plot Expression returned from Function

Suppose we have a function that does something with its parameters, and then returns an expression containing an equality. I want to then use that expression in (Contour)Plot to visualize it. The ...
179 views

### Procedures on Functions That Remember Values They Have Found

This one can not remember the value. Code 1. f[x_] := f[x] = f[x - 1] + f[x - 2]; f = f = 1; f ?f The 2nd one can keep the value it finds. Code 2. ...
81 views

### A table of plots of different functions

I want to create a Table of individual Plots where the table's index-variable is a series of functions. For example: Take two ...
43 views

### Controlling Expansion of Functions

Suppose I had the following definitions const /: N[const] = 1 / Pi^2; f /: N[f[x_]] := const / x^2; g /: N[g[x_]] := Pi * Sqrt[f[x]] * x^2; Now for this example, ...
137 views

### Good Practice in Defining Numeric Functions

I would like to define numeric functions for Mathematica such that they behave 'nicely' in much the same way as the built-in numeric functions do. For example, consider the following numerical ...
112 views

### Extract Jacobian from FindRoot?

I have to solve a system of fixed point equations and then calculate the eigenvalues of the Jacobian at the fixed point. There are about 50 equations with 50 variables and they contain a lot of ...
57 views

### How to take limits in Fourier series?

I have a Fourier series which produces an impulse train of period j+1. In principle, it is given by ...
44 views

### How can I define a function using ArrayFlatten without using SetDelayed?

I created a matrix F2 using SparseArray and ArrayFlatten as follows: ...
88 views

### functions with mutiple variables and lines of calculations

I am almost a new user of Mathematica, my question is that how can I have something like a function or exactly a function that for example gets two inputs (a) and (b), then calculates a+b and a*b. In ...
29 views

### Problem with FormulaLookup and FormulaData

I'm not getting an answer when I type either: FormulaLookup["BinomialDistribution"] or ...
53 views

### Can't make this “If” clause work

I am writing a code that creates a population with a probability to die for each citizen. They all start with some age, and after each application of the function, it either kills a person or adds +1 ...
64 views

### How should I define the Cayley transform?

I am a beginner to Mathematica. I am trying to define a function which would evalute the Cayley matrix transform, namely taking a matrix $M$ such that $I + M$ is invertible to $(I-M)(I+M)^{-1}$. I ...
31 views

### Define a function of multiple arguments at a given point

Trivia I am using Taylor series expansions to solve a system of PDEs for a number of functions $f_1(z, \phi), f_2(z, \phi) ...$ The expansions are generated by ...
62 views

### Defining an mathematical operator

I'm trying to learn mathematica to use in my thesis. I have basic problems with definitions, calculations etc. Let me ask a question. I want to define anti derivative operator and derivative operator, ...
85 views

### General definitions of deeply nested functions without SetDelayed, “UpUpValues”

I'd like to assign an "UpUpValue" in a way generalized to any nested head surrounding the value for which the UpUpValue would be defined. That is, if a function ...
86 views

### Symbolic properties of Re and Im

I want to define a function f such that f[x] is real whenever x is real. So I define ...
51 views

### How to include Do loop inside the With statement?

I wanted to create a matrix by following way: ...
47 views

### Defining a function of a function with arbitrary variable name

Is there a way to pass a function into a function you write such that the function can be of an arbitrary variable? What I want to do is something like... ...
74 views

### Strange Behavior of Compile[] inside With[]

Consider, in the examples below, the difference between defining $n$ as a global variable or as an argument to function comp[], which includes a compiled function ...
119 views

### How can I get the progressive application of list of rules?

I have a very long list of rules, and using this list of rules I want to see how some elements evolve as I successively apply the next rules on the previous rule. Here is the simpler version of my ...
63 views

22 views

### Defining an iterated differential operator with compositions

I'm a bit new to Mathematica so this question might be a bit basic. Still, I could not find an answer. I wish to define a symbolic differential operator. Currently, I do something like the following: <...
112 views

### How to program a situation like the following in mathematics and generalize the process to other configurations?

Distribute the numbers from 1 to 10(view image) so that the sum of each row and each column is the same and a) the maximum possible b) the minimum possible (I put it from 1 to 10 for ease) I know it ...
65 views

### Tensorial functions

I need to solve a system of ODEs for a function that has a complicated tensorial structure. I believe that NDSolve can deal with this scenario since version 9. Yet, ...
129 views

### How does DirichletConvolve relate to Dirichlet convolution?

Mathematica's Help documentation on DirichletConvolve is economical, to say the least. It claims the function "gives the Dirichlet convolution of the ...
47 views

### Difference Between Set and Pattern in Mathematica

Ok, sorry if this is too basic, I'm somewhat new to Mathematica, but I keep making errors in my code because I'm not understanding the namespaces. So this part I thought I understood. ...
55 views

### NumericQ and unknown number of variable in a module-block

I have the following problem I want to address in an elegant way. I have a function of many variables f[x, y, z,...] I want to find the minimum with ...
57 views

### Better way for constant expressions in functions than storing as global variables?

For example, I wrote a function like this: inversions[list_] := Complement[ Subsets[{1, 2, 3, 8, 4, 7, 6, 5}, {2}], Subsets[list, {2}] ] But as you see, ...