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
1answer
28 views

Mapping Linear Model Fit Over An Arbitrary Number of sets

I have multiple sets of data, and I want to apply Linear Model Fit sequentially to each set of data. For example, below tstlst contains 3 data sets. Right now I ...
3
votes
2answers
108 views

How to declare a function as real in order to get rid of Conjugate in front of the expressions?

I have a complicated complex function containing some other ones that are real, f=f(A,B,C,...) ,where A=A(r) and it is real, for ...
0
votes
0answers
29 views

Defined Function fails to Evaluate [on hold]

I apologize if this post is below quality, and please request more detail if necessary. I have been having this issue recently: I define a function as such: f[a_list, b_]:= ..... For a standard ...
2
votes
1answer
48 views

Plot does not take range with OptionValue and PlotRange option

I am making a function that is to use Show to overlay a few plots of a function. I want the first Plot in ...
1
vote
0answers
56 views

creation a table from a default module [on hold]

I have used of bisection method for finding the root of a function: ...
6
votes
5answers
190 views

How to write an operator that acts on pure function (to give another pure function)

I would like to write an operator oper that acts on a pure function f with an undetermined number of arguments, with the syntax ...
4
votes
0answers
76 views

Is there an elegant way of delaying evaluation of `A==B` when calling a function that uses this pattern

Suppose I wanted to define a number of functions that accepts expressions of the form: ...
-1
votes
0answers
26 views

How to compare strings insensitive? [closed]

To compare str1 with str2 I would do StringMatchQ[str1, str2] What if I want the ...
-1
votes
0answers
54 views

How to make async functions? [closed]

Considering we have two functions func1 and func2: func1 func2 How can I make ...
0
votes
1answer
50 views

Functions becoming undefined when evaluated

I'm so confused I don't even know how to phrase my Question title. My function nextCol works until I use colLength, then ...
0
votes
0answers
19 views

Protected Tags Error [duplicate]

While trying to run this piece of code: ...
0
votes
2answers
76 views

How to define $x^n$ where $x=\pm 1$ and $n\in\mathbb{Z}^{+}$?

I do not know how I can define $x^{n}$ in Mathematica, where $x=\pm 1$ and $n=1,2,3,\ldots$. For even values of $n$ we simply have that $x^{n}=1$. While for odd values of $n$ we have that $x^{n}=x$. ...
2
votes
1answer
55 views

Custom display for constructed functions

In a similar vein to my previous question, is it possible to define a function that displays differently to its default? eg I would really like Binomial[a,b] to be ...
1
vote
1answer
44 views

Define operator with special characters [duplicate]

I have looked here which describes how to define operators. I was wondering whether there was a way to assign thes operators to special characters? eg Let $\odot:=(a+b)(ab),$ so ...
0
votes
0answers
57 views

Inverse Superposition

There are 4 tables that, I have written them as bellow: (m, n, s, and r are orthogonal basis. r.r=n.n=m.m=s.s=1, and m.n=n.r=...=0). a's, b's, c's and d's are coefficients and are numeric values. ...
1
vote
2answers
63 views

Setting constants in a function containing If

I'd like to set the constants in a function that uses If, after it's been defined, but my definitions doesn't seem to stick. Simple example: ...
1
vote
0answers
40 views

Defining a function with a subscripted head

How can I define a function with subscript? Forexample: f_alpha[x] = 2*x
2
votes
1answer
66 views

Type declaration for list arguments

How can I make f[n_Integer]=2*n valid for a list of integers? For example: f[nlist_Integer] := 2*nlist[[1]] does not work ...
1
vote
3answers
120 views

How do I make a definition/function/method as I would in Java/MATLAB/Python

I've been trying to figure this out for a few hours now and it's driving me nuts. I am trying to confirm that, after transforming a Schrodinger equation, that the new wavefunctions satisfy the new ...
1
vote
2answers
46 views

Insert several rows and problem with Return

I wanted to write myself a function that makes it possible to Insert several rows into one list. ...
1
vote
0answers
61 views

How to Implement a “Function Object” suitable for NDSolve and Finite Element Method?

I have a bunch of methods that shoud return an expression that behave like a function, i.e. an expression that, when supplied with suitable arguments, evaluate to something. A simple ...
2
votes
1answer
59 views

Working with a two-variable function with one input fixed

Here's what I know how to do: f[x_] := x^2 - 4 x + 4 Ordering[f /@ {1, 2, 3}] This will evaluate f at each point and rank their sizes. Here's what I really ...
9
votes
4answers
228 views

How to Thread with custom functions? Thread vs Map?

This function finds n given the nth prime: findPrime[n_] := If[PrimeQ[n], i = 1; While[Prime[i] < n, i = i + 1]; i, False]; This works: ...
0
votes
0answers
80 views

How to make a twice-differentiable function that approximates some data?

I have some time series data that I would like to approximate with a twice-differentiable function. Each time series has ~10,000 datapoints, so I definitely do not want a function that passes through ...
1
vote
1answer
43 views

Why this isn't a valid argument? [duplicate]

I am having truble understanding why F1 produces an error, since both time and velocity are the same kind of object: ...
1
vote
1answer
51 views

Change input parameter order in a function

I'm a beginner in Mathematica programming and I'm trying to understand how input parameters work in Mathematica's function. I encountered a problem with the sequence/order of the input parameters of ...
2
votes
3answers
128 views

Defining a 2-variable function over voronoi diagram

I am new to Mathematica & I am facing a problem as follows: I have created a Voronoi diagram and now I want to assign to each region, a value, i.e., I want to extend this Voronoi diagram to form a ...
2
votes
1answer
37 views

Strange behavior when defining a symbol/function pointwise

I am well aware of the fact that floating point number have finite precision, so one needs to be careful when comparing them. Still, I find it disturbing/surprising that the following input into ...
3
votes
3answers
69 views

Orderless storage of tabulated function values

I would like to elaborate on my previous question Function of arguments given in non-fixed order and a relevant related one Best practice of passing a large number of parameters to functions I find ...
0
votes
0answers
38 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
2answers
62 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 ...
3
votes
3answers
99 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
102 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
179 views

Converting multi variable expression into a function

So I have this rather complicated looking expression ...
6
votes
1answer
248 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
51 views

Iteration variable in Sum gets assigned the final iteration value

I've got a function which is defined iteratively via ...
2
votes
2answers
84 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
63 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
59 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
64 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
66 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
218 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
75 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
52 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
64 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
42 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
85 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
47 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
96 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
401 views

All integer should be equal

I have a list of 10 integers: ...