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
2answers
26 views

Function to list Collatz sequence doesn`t work

I am new to Mathematica and was trying to make a function that lists the Collatz sequence stating with a given number, but I can´t get it to work. Here is my function: ...
7
votes
2answers
2k views

Gram-Schmidt Process for Polynomials

I want to implement the Gram Schimdt procedure to the vector space of polynomials of degree up to 5, i.e. I want to find an orthogonal basis from the set of vectors $v=(1,x,x^2,x^3,x^4,x^5)$. The ...
1
vote
1answer
49 views

Defining a derivative on a custom function

I am trying to define a derivative that acts on a custom function, $f$, such that when it acts, it increments one of the arguments of by 1. f is not defined; I just want to use it to keep track of ...
2
votes
1answer
40 views

Dropping rational coefficients

I have a list of expressions (they all are exact numeric quantities, not containing any variables), some of them have integer or rationals coefficients, or complex coefficients with rational or ...
1
vote
3answers
104 views

Setting ::usage for variables returned from a function

What is the best way to achieve {v,u} = f[]; (* Returns value and usage description *) v::usage = u; from inside f, i.e., ...
0
votes
0answers
23 views

General formula for total derivative [on hold]

I have a real-valued function $f\{x, y(x)\}$, with $x,y\in\mathbb R$. I would like to compute the total derivative with respect to $x$ in Mathematica. However, I am not able to write exactly that ...
2
votes
1answer
49 views

Manipulating unevaluated expressions in nested function calls

This is a follow-up to my earlier question: Passing an unevaluated part of an association to a function I'm trying to create a modular dashboard that controls sound volume of an audio system ...
3
votes
1answer
314 views

NestList with a list inside?

I'm new to Mathematica, and was looking for more efficient ways to implement the Do loop below. a, ...
0
votes
1answer
48 views

Element assignment in matrix function

I have to define a function of two variables that yields a high dimensional matrix, with each entry containing a scalar function, that uses its coordinates in the matrix as input. like this: ...
32
votes
2answers
1k views

Variable naming changes everything

Bug fixed in 10.0.0 I am having a rather unusual problem I do not understand with Mathematica where renaming one of the variables of my function causes the function to stop "working". Here is the ...
2
votes
1answer
81 views

How to get numerical results from HeavisideTheta?

I have defined a table tab = {7.52521, 17.0083, 22.5678, 11.8707, 8.27799} and a function ...
19
votes
3answers
248 views

Is there a GraphicsPrimitiveQ (or a complete list of Heads of graphics primitives)?

For various reasons related to workflow associated with creating figures for journals, I am creating functions that will accept graphics primitives and a set of options and spit out a ...
1
vote
1answer
57 views

Min function for functions f1, f2, [closed]

There are several "min" functions in Mathematica. In the "Numerical" category, there is a "Min" function that works on a numerical list. Then there's MinValue for finding the minimum of a whole ...
0
votes
0answers
32 views
3
votes
1answer
128 views

How can you get the area of a region from an image?

Suppose we have a square of side "L" m, How can I calculate the hatched area, if the corners of the square are centers of circles. It can be generalized to any region? edit: This is the result I ...
11
votes
4answers
375 views

Is there a concise form of Which or similar conditional?

Suppose that I want to write a function fun that takes an Integer num as input, and returns ...
2
votes
1answer
46 views

Appending Delayed Evaluation

I have a function that need to be summed over all parameters given in a separate list. f[x_,y_,z_,n_,i_]:= (*Some function*); list={{n1,i1},{n2,i2},...}; I need ...
2
votes
2answers
135 views

Multiply pure function with scalar

Somtimes I still get lost in the Hold, HoldAll etc. functions of Mathematica. I want to scale a simple PDF function with a previously calculated variable e.g. ...
0
votes
1answer
45 views

Finding function by constraints

I have the following coefficient finding problem: f[x] := a * Log[b*x + c] + d Constraints: f[0] = 1 f[80] = 0.5 I want to find the coefficients of f that ...
1
vote
0answers
52 views

function of a function [closed]

I have the following two functions, 'f' and 's': ...
30
votes
1answer
523 views

which is better, using Assert[] or manual checks on arguments and other computations?

I never used Asserts in Mathematica, but trying to see what advantage they have over just argument check and additional definitions of the function to capture unwanted input. For example, which one ...
8
votes
5answers
345 views

How to check the style and number of arguments like the built-in functions?

Given that I have a function sqrt[x] that I must check the style and number of argument x. I can do like this: ...
0
votes
1answer
40 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
269 views

Multiplicative partition function

I am trying to create a multiplicative partition function that would generate something like ...
3
votes
2answers
114 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 ...
3
votes
3answers
74 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 ...
1
vote
0answers
60 views

creation a table from a default module [closed]

I have used of bisection method for finding the root of a function: ...
6
votes
5answers
203 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 ...
7
votes
1answer
239 views

Two identical functions give different answers

I am new to mathematica and I hope this is a simple problem. I have two identical functions that only differ by the variable names: ...
2
votes
2answers
294 views

Writing a function that returns a (usable) function

I am trying to create a function that returns Arnold's Cat Map of size n iterated k times. I can get something out of the Function command, but I can't figure out ...
2
votes
1answer
52 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 ...
4
votes
0answers
80 views
1
vote
1answer
51 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 ...
31
votes
1answer
640 views

How to augment the realm of functions Mathematica thinks it knows how to integrate symbolically

My question involves extending the functionality of Integrate over specific integrals in the most generic manner. Specifically, is it possible to "hack into" ...
3
votes
2answers
143 views
0
votes
0answers
19 views

Protected Tags Error [duplicate]

While trying to run this piece of code: ...
15
votes
2answers
465 views

Quick way to use conditioned patterns when defining multi-argument function?

I have a simple function that is supposed to only accept numeric values (i.e. complex/real numbers and constant symbols e.g. Pi, E). $$f(a,b,c)=a+b+c$$ Edit: I should have chosen a less simple ...
19
votes
3answers
746 views

How to program a F::argx message?

How useful is it to program a user-built function in a package to produce a red warning message F::argx if you give the wrong number of arguments to that function? ...
0
votes
2answers
77 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$. ...
23
votes
3answers
1k views

Using pure functions in Table

I need a table with the elements made of pure functions and list elements. This is a simplified example: I need a list as: ...
0
votes
0answers
60 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. ...
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
45 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 ...
1
vote
2answers
64 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
3answers
131 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 ...
12
votes
1answer
557 views

Lazy lists of Tuples and Subsets

I'm trying to build a lazy list that evaluates the n'th m-tuple or subset of a given list using Mathematicas ordering without calculating all the Tuples. The purpose is to allow for example the ...
1
vote
0answers
41 views

Defining a function with a subscripted head

How can I define a function with subscript? Forexample: f_alpha[x] = 2*x
30
votes
4answers
1k views

Can a function be made to accept a variable amount of inputs?

I have a function that takes two inputs and processes them for a single output. What I need is one that can take a varying number of inputs. and process them to a single output. Is this possible in ...
2
votes
1answer
68 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 ...
9
votes
5answers
309 views

Function for a series of joined slopes

I need a function for a series of joined slopes and my solution feels a bit kludgy. Is there a better way? A list of pairs of transition points and slopes: ...