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

0
votes
0answers
9 views

Constructing a function for expanding general $n$ products

I have the following quantum mechanically motivated product: $\langle0\vert(A_1b_1 + A_2b_2 + A_3b_3)(B_1b_1 + B_2b_2 + B_3b_3)(C_1b_1 + C_2b_2 + C_3b_3)$, where $b_i$ is an annihilation operator ...
0
votes
1answer
37 views

Construct a function whose definition depends on the values of its arguments

I have to evaluate the components of a 6x6 matrix $S$. This matrix depends upon the semi-axes of an ellipsoid $a1$, $a2$ and $a3$. For various specific cases (sphere, prolate spheroid, oblate ...
1
vote
2answers
66 views

How to force evaluation on the right of an @ operator?

Is there a way to force evaluation on the right before the Prefix operator (@) without using parentheses? I came across this question when I was working with the ...
2
votes
3answers
97 views

Problem with the output of a function I program

(This is the function that I programmed) Zm2[Z_, nk_] := (zm2 = 0; For[i = 0, i < Length[Z], i++, zm2 += nk[[i]] *Z[[i]]* Z[[i]];]; Return[zm2];); ...
3
votes
5answers
171 views

Converting multi variable expression into a function

So I have this rather complicated looking expression ...
6
votes
1answer
234 views

Compiling a function that takes lots of optional arguments

I have a function that takes lots of optional arguments (basically some design parameters, about 10 of them) and performs some basic algebraic calculations involving complex numbers with the options. ...
0
votes
0answers
47 views

Iteration variable in Sum gets assigned the final iteration value

I've got a function which is defined iteratively via ...
2
votes
2answers
76 views

Need help with code for number theory problem

I'm completely new to Mathematica (used previously only for very simple cases). I need to write a quite complex function. The function must do the following: Input consists of two numbers: a and b. ...
3
votes
0answers
59 views

How to match the arguments of the function in any order

The issue is the following, with a dumb function with (4) arguments of (4) different heads (for each head is always no grater than one arguments): ...
1
vote
2answers
58 views

How to generate commands which are very similar?

I have several data sets that I wish to interpolate and integrate like this: ...
1
vote
1answer
56 views

Retrieve XML Tree with only specific XMLElements

I would like to retrieve the XML Tree of a XMLObject with only specific XMLElements. In the help of Mathematica ...
1
vote
1answer
64 views

Constructing an I-graph

I am attempting to build I-graphs in MMA, i.e. the non-Generalized Petersen graphs, and I found some code from Eric Weisstein, but this is now outdated and doesn't run. I have attempted to switch the ...
13
votes
2answers
187 views

Clean and handy Options management/filtering

the case I want to be able to create a function with some default options but also without need to add full explicit list of options available for it. And then inside I want to be able to filter ...
2
votes
2answers
69 views

Creating a bump function on a spline region [closed]

For a presentation, I'd like to include a 3D plot of a function of two variables x,y with the properties that (a) it looks "smooth" i.e. without jagged edges and (b) has support equal to a given ...
1
vote
2answers
50 views

Subsituting expressions for expressions

I'm trying to define functions using other functions, like so: f[a_, b_] := a/b; a[c_] := c; b[d_] := d; Now what I want to be able to do is two things: ...
0
votes
2answers
59 views

Plotting vectors using derivatives

This question stems from a previous question I asked here: Multiple Integral of equation including dx prime? An equation describing a gravitational field of a cuboid is given as: $V(X,Y,Z) = -G\rho ...
0
votes
0answers
35 views

Multiple Integral of equation including dx prime?

I'm hoping someone can verify I've written this function properly since I'm a little new to Mathematica. What I'm attempting to do is code a function that describes a gravitational field of an ...
3
votes
2answers
82 views

How to use an expression for the argument to a function [duplicate]

I would like to define a function over a list of variables like f[a_,b_,c_]:=a+b+c However, when this list is big it makes uncomfortable to read. Can I somehow ...
2
votes
0answers
44 views

Construct single InterpolatingFunction from a mathematical combination of other IF's

Let's say I have an interpolated function f, like I might get as the solution to an NDSolve: ...
6
votes
2answers
89 views

Optional arguments with lists as function parameter

I'm developing a function f which should support optional arguments {x_, y_} in list form. A simple example looks like this: ...
4
votes
6answers
394 views

All integer should be equal

I have a list of 10 integers: ...
5
votes
1answer
82 views

Is Sow/Reap compatible with Composition?

I'm trying to figure out why these two pieces of code return different results. As expected, f[Reap[Sow[x]]] gives ...
0
votes
1answer
38 views

How to have default case in Which? [closed]

Saying we have a function: a[x_] := Which[x === 1, "AAA", x === 2, "BBB", _, $Failed] How can I make this function to be equal to ...
0
votes
1answer
83 views

How can I generalize this interpolation function? [closed]

I have a data set where I want to evaluate a manual interpolation function. The part shown below expands up to the 7th power currently. I was wondering if it was possible to generalize this part of ...
2
votes
1answer
55 views

Is there a shorthand for Optional with Condition?

I have a recursive function that does some work to an object for a repeatedamount of times. ...
2
votes
3answers
77 views

How do I map a function onto the result of an expression that already has a pure function as an argument

I admit that I have only a basic understanding of the way Mathematica handles pure functions - enough to be dangerous, unfortunately. I have some data that is in a list of lists of lists. I would ...
0
votes
0answers
39 views

Using list of values as argument in a function [duplicate]

could you please help me with a task. I would like to define a function with a list of values as an argument. There is a working code with a values {1,1,1}: ...
1
vote
2answers
63 views

How to make function accept list of rules as an argument?

Considering the list of rules: r= {"a" -> "1", "b" -> "2", "c" -> 3, d -> 231, "e" -> 1.25}; I want to have a function ...
1
vote
2answers
141 views

Minimizing the largest difference between two functions

I have two functions defined on the same domain, $f(x)$ and $g(x)$ where $x$ is in $(0,1)$: f[x_] := (-1 + x) Log[1 - x] - x Log[x] g[x_] := Log[1 + 2 (-1 + x) x] ...
2
votes
1answer
76 views

What is the meaning of two square brackets in function definition? [duplicate]

I came along the following function definition f[a_, b_, c_][r_] = ... with some function on the right hand side. Is this equivalent to ...
0
votes
0answers
25 views

How to create a big jacobian matrix function over some variables of a vector function?

Suppose I have a vector function of $n$ components and it has $n+m$ arguments, $$\vec{f}(x_1,x_2,\dots,x_n, y_1, y_2, \dots, y_{m})$$ where $n, m $ are around 10. I want to create a Jacobian matrix ...
3
votes
2answers
66 views

General function for the expansion of a polynomial of operators

This question is motivated by a Quantum mechanical problem - but in explaining the problem - I assume no knowledge of quantum mechanics. I want to define a function that can expand and simplify the ...
0
votes
0answers
24 views

Function with variable arguments [duplicate]

I wrote a function with three arguments like this f[a_,b_,c_]:=... When I call this function MMA requires the input of all three arguments (e.g. f[1,2,3]). Is ...
-1
votes
1answer
47 views

Create a list of all functions given a set of arguments

I'm trying to examine some patterns on the permutation of elements in finite element functions. I'd like to create a list of all functions (256 of them) on ...
2
votes
2answers
77 views

Dynamic updating of Slot number [duplicate]

I want to change the slot number inside Manipulate[]. Here is a minimal example which does not work: ...
-1
votes
1answer
75 views

I have several functions and how I know which one is the maximum in a certain range?

What I did are the followings These lines will generate a piecewise function pw which tells me the corresponding variable given an interval as follows: Now, I want to get: names of variable ...
0
votes
1answer
84 views

Simplifying code

I have a program where I solve the Lorentz-63 system (system of ODEs). I wish to generalize my program to make my code cleaner. Is there any way to create a function that works in a fashion such as ...
0
votes
0answers
43 views

Piecewise function output response interpretation

Piecewise[{{t^2, t <= 0}, {t, t >= 0}}] Outputs: t^2 t <= 0 t t >= 0 0 True What does the last line of output 0 True mean? Sometimes it ...
1
vote
1answer
43 views

Defining functions that depend upon other functions which depend upon other functions and so on

The problem is that I have to evaluate functions, that take output from previous functions, and combine them to form new functions, and do some operations and evaluate the value at new function. But, ...
4
votes
1answer
118 views

Map at a subsequence of a list

I'm trying to construct a function somewhat similar to MapAt. A basic usage example should look like this: ...
0
votes
1answer
51 views

How to define the following bracket?

My quetion is about the definition of the so-called Courant Bracket. Given two generalised vector field, defined as a formal sum of a vector and a one-form, i.e. $X = x + \lambda,\ Y = y + \omega$, ...
7
votes
1answer
93 views

Context-dependent functions

TL;DR warning! My question is not about getting the length of the ticks correct (although if someone has good suggestions, that would be welcomed). My question is about constructing functions that ...
1
vote
2answers
79 views

Avoid nesting of functions [closed]

is there a way to avoid the "nesting" of functions like f[f[f[a, b], c], d] where a, b, c, d are lists and f is a function that merges two lists with certain ...
0
votes
0answers
37 views

How can I get the covariance result cumulatively?

I am trying to derive the covariance results for n x 4 matrix where n is an arbitrary number. I am trying to derive the covariance for each row cumulatively. For example, I am trying to derive the ...
2
votes
2answers
136 views

Using list elements as function calls ?

Is it possible to take elements of a matrix or list and use them as arguments of a function? I have a matrix of values, something like this; ...
0
votes
0answers
36 views

NestList on a function where one of the arguments is chosen by the user

I need to NestList a function where the user chooses one of arguments. Here it is an example: ...
0
votes
1answer
56 views

Creating a symbolic function dynamically given an array of data

I have a function that is based on the numeric values of a random sample that I would like to maximize: ...
4
votes
1answer
115 views

How can I implement this recurrence equation in Mathematica?

I asked a similar question yesterday but today I realized that I was implementing the wrong function. I have tried changing the implementation but I can't get it to work. Problem: There is a river ...
2
votes
2answers
177 views

How can I express this recurrence function in Mathematica?

\begin{equation} r_{i+1}=r_{i}+V_{i}{\Delta}t \end{equation} Where \begin{equation} V_{i}=(0.01, 0.40) \end{equation} and ${\Delta}t$ is the difference in time. My implementation (this is for ...