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.

Filter by
Sorted by
Tagged with
1 vote
1 answer
60 views

How to define functions using $Z_2$ coefficients and $Z_N$ variables, e.g, realizing $1+1=0$?

A minimal example is to realize the following: $x+x = (1+1)x = 0$, and $x^{N+1}y^{N+1}=xy$, where $N$ is a given positive integer.
  • 111
0 votes
1 answer
75 views

Mathematica function defining problem

The "F" function is defined as mentioned, but when I call the function F inside the code, "F" can't compute value using the function F, just give F_0, F_1, etc. Can somebody guide ...
  • 1
0 votes
0 answers
43 views

How to double sum or triple sum up over the list of functions?

I'm dealing with a summation problem by now using a list of function $F(x; \theta_i)$. The function is defined as \begin{align*} F(x; \theta) = 1 - \Phi[\Phi^{-1}(1 - \frac{x}{2}) - \theta] + \Phi[-\...
0 votes
1 answer
43 views

Simulate a binomial distribution experiment

I am trying to write a user-defined function to simulate a binomial experiment as following: ...
-1 votes
1 answer
76 views

How to create this function? [closed]

Let vowels:= {"A","E","I","O","U"} Let alphabet be some CharacterRange, i.e.: ...
5 votes
2 answers
266 views

Declare a function with symmetric arguments

I have a package that contains a function f[a_,b_,c_] which is explicitly symmetric but only in its first two arguments. How do I make Mathematica simplify things ...
  • 651
4 votes
1 answer
67 views

Verbose `Dynamic` variable lists

Is there a way to achieve the following without listing all of the dynamic pieces so verbosely / manually listing all the dynamic variables? ...
  • 8,005
3 votes
4 answers
127 views

Display subscripts and superscripts using conditions on Format

I have a simple function Eps[a,b] that I want to display as a a particular symbol. Currently I have the code: Format[Eps[a_, b_]] = Superscript[\[Epsilon], ab] ...
  • 651
2 votes
1 answer
58 views

Syntax for nested If statements

This seems an awfully long-winded way to achieve the following: ...
  • 8,005
0 votes
0 answers
41 views

Unable to access Options from an outer function

Like most coders, I hate writing variables as strings. Symbol options among other Options assists its designed for, is also ...
  • 2,009
2 votes
1 answer
71 views

How to plot a function with different conditions (if or which or piecewise)

The given function is This function is plotted to be ...
  • 664
2 votes
2 answers
170 views

Trouble understanding function composition?

I made the following code: Cs = {{0, 1}}; f[x_] := (Clear[s]; s = (x[[2]] - x[[1]])/3; Splice[{{x[[1]], x[[1]] + s}, {x[[1]] + 2 s, x[[2]]}}]) Observe that we can ...
  • 4,911
0 votes
0 answers
42 views

How to find the sequence function $f(n,x)$ of the three given functions?

I have the three functions $f(2,x)$, $f(3,x)$ and $f(4,x)$ where $x>0$ ...
  • 463
2 votes
1 answer
113 views

When to use f:= x vs f[x_]:= x?

I have many compound functions, using the same variables. I can define them like this: f[x_,y_]:= ... g[x_,y_]:= ... h[x_,y_]:= f[x,y] + g[x,y] or like ...
8 votes
1 answer
133 views

Best practices or hidden drawbacks to define multiple-argument functions

I was wondering if there were any important differences or stylistic considerations for deciding between different ways to define functions of multiple variables, e.g. ...
  • 1,600
1 vote
1 answer
42 views

How to better display the data using ComplexListPlot?

I'm trying to plot the solution of the equation with ComplexListPlot but the plot of the data points are small and hard to see. Do you have any idea to display it better and easier to see the data? <...
  • 2,484
10 votes
1 answer
167 views

How to programmatically construct a function or a compiled function?

I'd like to programmatically construct a function from a long expression with many duplicate terms. The objective is to programmatically create a set of compiled functions with expressions that were ...
  • 2,881
3 votes
1 answer
52 views

Is it possible to name a pattern within a repeating pattern during function construction?

Question I would like to know if it is possible to have a named pattern within a repeated pattern during function desctiption. For example: f[(a_)..]:= Why I am ...
3 votes
2 answers
68 views

Define functions collectively depending on an input parameter

I'm developing a package, and one of its functions is param, which reads a rather big file and extract one of the parameters in there. I have a few more functions, ...
  • 185
0 votes
0 answers
38 views

How to apply the map function to NMaximize to build a 2*2 table?

I have a single variable function, named globalprofitfuntion[beta]. I am using NMaximize to locate its maximizer, beta*. This function has four parameters: cv,cr,k and w. To perform sensitivity ...
5 votes
3 answers
208 views

How to automatically interrupt `Set` with conditions

Maybe this is a bad idea: I want to inject some conditions into Set associated to specfic symbols, like ...
  • 667
2 votes
1 answer
102 views

Function Parameter Substitution Problem

I have this function ...
  • 415
0 votes
0 answers
25 views

how to set a function with a default value for some of its variable? [duplicate]

I wonder if there is a way to set a default value in a function definition. For example, I set up a function f[x_, y_] := (x + y)*2 I would like to set the default ...
3 votes
1 answer
88 views

How to get $(1-x^2)^{1/2}\theta(1-x)$ continuous?

The function $f(x)=(1-x^2)^{1/2}\theta(1-x),$ where $\theta(x)$ is the Heaviside function, should be a continuous function for $x\geq-1$. Another way to define the same function is, $$ g(x)= \begin{...
  • 33
1 vote
1 answer
38 views

How to define a function as an operation on the other option

I would like to define the function g as the Laplacian of the function f as follows: ...
5 votes
2 answers
201 views

How to define functions of functions

I'm trying to define a function, call it "L", which itself is a function of other functions, such as: L[x[t], y[t]]:= x'[t]+y'[t] Then, I want to take a derivative of L[x[t], y[t]] with ...
3 votes
3 answers
96 views

How to make my function to thread over additions?

I have a function f[x]. Can I make it to thread over sums automatically? I mean I want to declare it distributive against addition.
  • 2,940
1 vote
2 answers
92 views

Apply function to the second level if the first level is integral from zero to infinity, otherwise, not evaluate

How can I make a function, say, R[expression] such that it works on arguments like this Integrate[f[x],{x,0,Infinity}], applying ...
  • 2,940
4 votes
1 answer
85 views

OptionValue not inserting correct option

I am using OptionsPattern and OptionValue to define some switches for my custom function. Here is a minimal example: ...
  • 557
0 votes
2 answers
86 views

How to print the function of $f[n]==f[n]$?

The funciton is as follow,and n can be 1,2,3... f[n_] := n + n^2 + n*a + (2*n + 1)*b; f[1] f[2] ...
  • 19
0 votes
1 answer
56 views

How to avoid the endless loop and remove the definition?

The function ...
  • 19
1 vote
2 answers
148 views

Package the code into functions [closed]

I use ...
4 votes
3 answers
267 views

How to create a sequence of functions defined recursively?

I'm trying to create a Table of functions where each new element is defined recursively via indefinite integration of the previous one. I've tried doing: ...
  • 49
3 votes
3 answers
160 views

Find first position satisfying condition, which is true after a certain element

Can we find the first position of elements of a list satisfying a condition, with good performance, if the conditions is a tail condition of the list. What is tail condition ? (the term is informal, ...
  • 3,231
1 vote
1 answer
53 views

How do I construct and plot functions properly using NestList?

I am trying to construct a function using NestList and plot the values. Although the individually used and defined functions in my notebook seem to do the right ...
3 votes
2 answers
314 views

Define functions by ‘List’

Let's say I now have a set of variables {x,y,z},I define functions in terms of x,y, and z,I can do that f[x_, y_, z_] := x + y + z The downside of this definition ...
2 votes
1 answer
122 views

How to give a property to a list of functions?

For example, I have defined a bunch of binary functions Sum1, Sum2, Prod1, ...
8 votes
2 answers
116 views

Constructing a RootSum object changes existing internal syntax

Bug introduced in 9.0 or earlier and persisting through 13.0.1 or later I noticed that initially valid syntax becomes invalid within nested RootSum objects. ...
  • 2,979
9 votes
3 answers
657 views

What is the best method to search pattern for 2D list?

What is the best method to search patterns for 2D list ? Let L be following 2D-list : ...
  • 3,231
2 votes
1 answer
90 views

How to define function which changes at certain condition

...
1 vote
1 answer
66 views

Why does my simple string function fail to grab the only element in a List?

The idea is to normalize a string before processing it to extract information from it. Strings may come with embedded outer brackets which are easily stripped or as elements of a true list. This is ...
  • 2,009
2 votes
1 answer
59 views

Can substitution rules be used in function definitions?

Simple input like this f[x_]:=2x f[2] has the predicted output of 4. However, this r={a->2x}; f[x_] := a/.r f[2] Produces ...
  • 187
2 votes
2 answers
72 views

Piecewise based on the length of the list

I want to create a piecewise function that depends on the length of the list. Let's say I have a list, and a corresponding piecewise function: ...
  • 857
0 votes
1 answer
64 views

Create list with integer partitions satisfying some conditions

I want to create a function PartSet[N_,M_] of two positive integer variables which outputs a list of all pairs of integer partitions for all integers up to $M$ ...
  • 1,307
4 votes
1 answer
133 views

How to add ticks for mesh?

I'm trying to reprocedue this plot with Mathematica and got some problems. ...
  • 2,484
11 votes
1 answer
260 views

Association vs Pair - Creation performance, Selection performance

Suppose that we ...
  • 3,231
4 votes
1 answer
75 views

Replacement, PatternTest, Module related Question

Let's see how MMA handles following type of expression : Replace[L, {pattTest1->rhs1, pattTest2->rhs2, pattTest3->rhs3}, {1}] Specific example : ...
  • 3,231
3 votes
1 answer
81 views

Classifying elements, by the value of a fixed function, using Replace

Let L be a list of several lists. And the length of each list is less than 1000. You can create L by ...
  • 3,231
1 vote
1 answer
93 views

While inside a function body does not work as expected [closed]

I'm trying to write a function that return a randomly created rational polynomial function that has a discontinuities points. I already have a function that generates random rational polynomial (...
  • 69
0 votes
1 answer
101 views

get positions satisfying multiple criteria

Given a list L. It is mathematically proven that there is no element in L matching 2 or more patterns in ...
  • 3,231

1
2 3 4 5
45