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,965
questions
1
vote
2answers
80 views
How do I write a multivariate function? [closed]
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/...
3
votes
0answers
73 views
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:
...
0
votes
1answer
47 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 ...
7
votes
2answers
136 views
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 ...
2
votes
2answers
68 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
...
0
votes
2answers
101 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.$$
...
2
votes
2answers
145 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 ...
2
votes
1answer
96 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.
...
0
votes
2answers
58 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 ...
4
votes
2answers
196 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[1] = f[2] = 1;
f[5]
?f
The 2nd one can keep the value it finds. Code 2.
...
2
votes
2answers
113 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 ...
1
vote
1answer
45 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, ...
6
votes
2answers
183 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 ...
7
votes
1answer
152 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 ...
1
vote
2answers
66 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
...
0
votes
1answer
54 views
How can I define a function using ArrayFlatten without using SetDelayed?
I created a matrix F2 using SparseArray and ArrayFlatten as follows:
...
0
votes
0answers
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 ...
0
votes
0answers
30 views
Problem with FormulaLookup and FormulaData
I'm not getting an answer when I type either:
FormulaLookup["BinomialDistribution"]
or
...
1
vote
1answer
55 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 ...
3
votes
1answer
71 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 ...
0
votes
1answer
32 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 ...
0
votes
0answers
65 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, ...
3
votes
1answer
90 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 ...
2
votes
2answers
98 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
...
0
votes
1answer
51 views
1
vote
2answers
54 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...
...
2
votes
3answers
83 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 ...
6
votes
1answer
120 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 ...
1
vote
0answers
67 views
Is there a function to convert a trigonmetric expression to an algebraic expression suitable for ComplexPlot?
According to H. A Priesley:
"both $cosĪø$ and $sinĪø$ can be written as simple algebraic functions of
$z$":
$cosĪø =\frac{1}{2} (z + \frac{1}{z}) \tag1$
$sinĪø =\frac{1}{2i} (z ā \frac{1}{z})\...
6
votes
1answer
91 views
How to get smooth square root of complex valued function?
Let $f(x)$ be smooth complex valued function with real argument $x\in[0,1]$.
I want to get square root $g(x)=\pm\sqrt{f(x)}$ where the sign is chosen so that g(x) is smooth. How can I do that?
In ...
0
votes
0answers
50 views
Functions of several variables composition
If we have two functions $G,F:\mathbb R^2\to\mathbb R^2$ then the mechanism
$F\circ G(x,y)=F(G(x,y))$ gives us a new map $F\circ G:\mathbb R^2\to\mathbb R^2$ called its composition.
In a "...
6
votes
3answers
417 views
Iterated differential operator
I would like to implement the following differential operator in Mathematica,
$$
\prod_{j=1}^n \left({\mathrm d \over \mathrm d x}-j\right)
$$
On a case by case basis, I can just expand it out and ...
2
votes
0answers
58 views
How to define tensors similar to Riemann tensor in xAct xTensor xTras
I'm working on a project where we deal with objects very similar to Riemann tensor. In fact they are Christoffel symbols for higher spins. I'm using xTras for modeling problems in wolfram mathematica. ...
5
votes
1answer
129 views
How can I emulate Orderless attribute?
Suppose I want an expression to automatically sort its arguments. This can be done via
SetAttributes[f, Orderless]
f[3, 2, 1]
(*output is f[1, 2, 3]*)
Just as an ...
7
votes
4answers
219 views
How to use each replacement only once in a list of replacements
I have a list of replacements and some list they are acting on. However, some RHS of the replacements rules are identical (the LHS is not). I want to use those rules one after another (perhaps cycling ...
1
vote
0answers
49 views
How to find the Inverse of numeric Function that was created from NDSolve
I'm a newbie to Mathematica and i do have a simple question.
I have a function H that was created numerically as solution form NDSolve (like H(R)), and i'm trying to create the Inverse function R(H) ...
0
votes
1answer
54 views
How do I introduce an assumption when defining a piecewise function?
Define m as an integer. I want to specify a Piecewise function f[x,n] that takes value ...
3
votes
0answers
67 views
Prime Matrix with determinant of powers $2^x$
Mathematica has commands for finding prime matrices, for example, here is a matrix with randoms in the range $<100$:
RandomPrime[100, {3, 3}]
This $2 \times 2$ ...
1
vote
1answer
32 views
Method to determine a set contains rational whose denominator is 2
Suppose S is a set of (complex) numbers.
I want to know whether S contains rational whose denominator is 2.
For example,
when S={1,2,3,4,1/4}, return "False".
when S={1,2,3,1/4,-5/2}, return ...
2
votes
2answers
156 views
Shortest way to take first half of list and/or split list into n parts
What is the shortest way to take the first half of a list? Or to split a list into n equal parts? If the length is not 0 mod n, I would prefer to leave out the left ...
0
votes
3answers
180 views
How to write a custom function to judge whether a bivariate function is differentiable at a certain point?
We know that the necessary and sufficient conditions for a multivariate function to be differentiable at a certain point are complicated:
Suppose the function $z = f (x_ 1, x_ 2, ..., x_n) $ is ...
1
vote
2answers
32 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:
<...
2
votes
2answers
125 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 ...
1
vote
1answer
80 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, ...
4
votes
2answers
134 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 ...
2
votes
1answer
51 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.
...
3
votes
1answer
60 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 ...
3
votes
2answers
64 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, ...
4
votes
1answer
235 views
Having difficulty plotting linear system of equations
I have a function eqsfromMatrix[..] that generates linear equations from a matrix which I would like to plot but there seems to be no direct way to plot them. I ...
1
vote
1answer
46 views
Cannot get conditional Take[…] from List[…] to work inside a user-defined function
Abstract I have a function eqsfromMatrix[...] that does exactly as it sounds. It returns a list of equations given matrix m for ...