# 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.

2,105 questions
Filter by
Sorted by
Tagged with
22 views

### Interpolation of a set of points that include a non-numeric real constants

I have a set of data like: matrix=Table[{x,y,x+y*c1},{x,0,1,0.1},{y,0,1,0.1}] where 'c1' is a real constant. I'm trying to create an interpolation function called '...
30 views

### Calculating an unsimplified expression containing derivative of an expression which is substituted instead of a function

I have the following expression: Derivative[0, 1][Integrate[E^(-(n*\[Tau]) - I*k*y*Cosh[\[Tau]])*B[\[Tau]], \[Tau]]][x, y] which is created by substitution of a ...
40 views

### Detecting whether a function is initially defined with the form R[x,y] or R[x_,y_], etc

I have a very long code that may have errors in definition of functions and I want to trace these errors. Is there any attribute or function to detect whether a function is initially defined in the ...
52 views

### Changing part of the name of the function

Is it possible in Mathematica to replace the part of the name of the function to give the same arguments to another function? In fact, I have a lot of functions with the following name pattern: ...
27 views

### How can I extract a list of terms with functions in terms of a specific variable

I have an expression in the following form: a f[x] + b Exp[g[x, y]] + r[z] f[y] + f[y] Sin[h[x, y, z]^2] + r[z] Log[t[z, y]] I want to extract an expression ...
186 views

### Defining a function recursively

I want to construct polynomials (or just function) $f_n$ from $f_{n-1}$ using mathematica. For some kind of reason, I didn't manage to do this. So basically something like a recurrence table, but for ...
152 views

### Permutation avoidance function

It is common for me to see if a permutation of 1,2,...,n, avoids some fixed permutation pattern. For example, the permutation [1,4,2,3,5] contains the pattern 1,3,2, as the elements [1,4,3] appear in ...
76 views

### What's wrong with SetDelayed? The body of the function works alone, while setdelayed to it as $f[x\_]:=func$ gives the wrong answer

So I was writing a function to get the poincare map of a given dynamic system, for example, the duffing oscillator. I obtained the time series in advance, then take the poincare map based on this time ...
48 views

### How to make a function in terms of constants to inherit the attribute of being constant

I have defined two variables a and b: SetAttributes[a, Constant]; SetAtributes[b, Constant]; I have defined a function c as ...
38 views

### How to assume some variables to "not" be a function of other variables at the time of defining a function [closed]

I have a function with the following definition: F[x]=Exp[q*w*x]; I want to take total derivatives of F. How can I define that q and w are not dependent on x at the ...
39 views

### How to separately pass elements of a 3D list as part of the arguments of a function

Hi I have a function which its arguments have the form F[a,b,c,d,e] but the 2nd to 4th arguments are in a list of the form R={{{b,c,d},{e,f,g}},{{h,i,j},{k,l,m}}} how can I pass these elements as ...
51 views

### Partially Orderless Arguments in Functions

I am a Mathematica beginner and I'm trying to implement a function of type f[i1_,i2_,i3_,i4_] such that it is orderless in the first two arguments and in the last ...
43 views

### How to define a function without giving explicit formula

I want to have a function and I need to do some complex calculations to obtain an equation and then I want to assign the values to the function and then solve this equation to obtain the unknown ...
129 views

### How to Create an Efficient Word Square Algorithm?

I am working on the Wolfram Challenge Babbage Squares. I have looked at the following resources in order to come up with an idea for how to find all the possible word squares: Word Squares and Beyond ...
47 views

### Loops Not Working- Kernel Crashes and Values Incorrectly Updated

I haven't used Mathematica in a while so any help is very greatly appreciated. I am trying to run a program with nested for loops that runs two function evaluations in the inner most part of the loops....
27 views

### How to turn FindFit result into function within a Module context

I'm trying to construct a 'normal' function (with formal parameter) from the FindFit result within a Module context. While this works on a global level: In := ...
46 views

### How to create a simple transformation function on lists using short form of ReplaceAll?

I can easily do this with Map so the real goal of this exercise is to get a better grip on using transformation rules. Please help with this. The outputs should be ...
42 views

### Silly trouble expressing recursive formulas?

I am trying to code the following formulas: I did it in the following way: ...
59 views

### Is there a comprehensive list of most common or most important native Message-s (w/tags) for errors and Failed?

Yes I understand how to use Messages[symbol] but that doesn't help much. I have no idea which important ones I may have missed in my search or even how many exist. ...
58 views

### Recursively rewrite function

Let's imagine I already have a function like myfac :=1 myfac[n_ /; n>=0] := n myfac[n-1] this home grown factorial. Now I want to equip it with tracing (and ...
48 views

### Could anyone help me to plot the following function? [closed]

Unfortunately Mathematica is not able to run the following program area[d_]:=Pi*d^2/4 Q=80/1000 v[d_]:=Q/area[d] [Nu]=10^-6 Reynolds[d_]:=v[d]*d/[Nu] [Epsilon]=0.04/1000 CW[[Lambda],d]:=1/Sqrt[[Lambda]...
20 views

41 views

### Define multivariate even general function

I want to define a multivariate even function. This question shows how to do it for a single variable function Defining general odd function but I don't see how to generalize the syntax to multiple ...
64 views

### How to clear all things inside a loop?

It happens to me a lot when I write a loop, I have to Clear all functions, variables, definitions and etc to be sure my calculations is done correctly. namely as a ...
40 views

### How can I set a find max value function with parameter in NDSolve

For example, Here is a NDSolve function with a parameter of w ...
35 views

### FoldList type evaluation for multivariable function

In the example code which follows I define a two variable conditional function h[_i, _v], one variable denotes the integer index i, and the other is an N-dimensional vector v (I denote dimension 'N' ...
297 views

### Why the first one works fine but not the second one?

Why the first one works fine but not the second one? How can I make it work? Abs[#] Exp[I Arg[#]] &@(1 + I) ...
30 views

### Force list of colours to have same grayscale value, maintaining hue

A sketch of what I'd like to achieve is given by ...
66 views

### Dynamic influenced by a countdown Clock ignores actions in second argument

I stripped a Dynamic down to its bare essentials. Dynamic doesn't execute any of the functions asked for in second argument. ...
88 views

### Function as a sum of functions

I just get started with Mathematica and I have a basic question about defining a function (I am sorry if this was asked before). I have 2 functions defined as: ...
117 views

### How to use Equal for close arbitrary precision numbers to be considered the same?

I am trying to add a comparator function in a larger piece of code which can equate two arbitrary precision numbers and yields True if they are approximately close. ...
196 views

### Looking for a Compilable Form of DeleteDuplicates

Union is Compilable but DeleteDuplicates Isn't?! First, DeleteDuplicates is not compilable ...
258 views

### IntegerQ[x] gives false. Just leave it as it is

Since x is an alphabet not an integer, Clear[x];IntegerQ[x] gives False But sometimes I ...
101 views

### Compile Can Handle Passing an Empty List Only When Returned by Some Functions?

There seems to be a bug whereby Compile can deal with empty lists only when passed in some cases. Consider the case below. ...
45 views

### How to make a vector of elements the pattern of a function?

if I have an expression that contains a lot of symbolic elements and I would want to make it a function of the vector containing all the elements I've found a solution based on rule delayed: ...
88 views

### How to make a function ignore an argument [closed]

Motivation I am trying to call a function f, that has either 1 or 2 (or multiple) parameters, from a function g that uses ...
53 views

### generate quadratic functions to evaluate membership of points

How can I make a printable list with different quadratic functions and with points that belong or not to them so that a young person can check whether or not the point belongs to the parabola? my code ...
263 views

### "instruction 9223372036854775807" Bug and Bug with Using DeleteCases[] inside Compile[]

I get an error referring to "instruction 9223372036854775807" as follows. I run the code ...
63 views

### Extract function argument sequence

Is it somehow possible to access and reference the sequence of arguments of a non-pure function? For example if I want to take the derivative with respect to the n'th argument, a pseudocode example ...
I have made a contour plot via Minitab and got an image like this one: With $z$ being the enthalpy $[BTU/lb]$ $x$ being the temperature $[°F]$ $y$ being the ...