Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
2answers
68 views

Define a partial derivative of a composite function

I would like to define the function $ \dfrac{\partial}{\partial y}\left(\dfrac{f(x,y)}{g(x,y)}\right)$, for example ...
5
votes
3answers
335 views

What is the the proper way to define a function from an expression?

Say after some long computation we get an expression expr=x^2 We do not know what the value of expr beforehand. Now we want ...
2
votes
1answer
38 views

How to define a function inside a module through Evaluate [duplicate]

I am trying to define a function inside a module as following ...
0
votes
1answer
33 views

Defining functions trouble [closed]

I'm a neophyte in Mathematica so this is a very basic question. I'm having trouble with defining the following functions: ...
1
vote
0answers
29 views

what the meaning of function definition in this form? [duplicate]

In the post Mathematica code for Bifurcation Diagram, I noticed that Mark McClure define a function like this: f[a_][x_] := a*x - 1.19 x^3; I wonder its ...
0
votes
2answers
77 views

How to compute the density of a Inverse Wishart Distribution?

How does one compute the density of the inverse of a Wishart distribution in mathematica? The MultivariateStatistics package only has the Wishart density, and not the inverse Wishart... Any help ...
3
votes
2answers
82 views

Truncate a set of lists until a subset of entries matches?

Consider lists of vectors of elements like ...
0
votes
0answers
16 views

Trouble restricting function images

I am following this book https://www.amazon.com/exec/obidos/ASIN/1558606378/ref=nosim/ericstreasuretro with mathematica and I'm having some trouble on my way: 1) Consider the function ...
0
votes
1answer
32 views

Is it possible to define a function like this f[K[1]_,K[2]_,K[3]_] [duplicate]

f[K[1] _, K[2] _, K[3] _] := 32 b^9 + 4 b^3 Cosh[b/2] K[1] K[2] - 4 b^3 Cosh[b/2] K[1] K[3] f[10,10,10] I have an equation which is a function of K[1], K[2] and ...
1
vote
0answers
34 views

Series doesn't seem to work on functions

When you try to use the Multivariable option of Series, it doesn't work as intended, since it keeps terms of higher order than intended. Example: Expand a two-variable gaussian exponential to second ...
0
votes
0answers
27 views

Defining a function that transforms an expression with rules

Question I try to define a function that apply a set of rules to an expression in Mathematica 11.3. However, the function returns a result that is not the same as directly applying the rule to the ...
0
votes
0answers
31 views

Define a function with singular Taylor expansion

With an undefined symbol f command Series[f[x], {x, 0, 1}] returns f[0]+f'[0] x+O[x]^2 ...
0
votes
1answer
21 views

Cut graph at a given edge and return remaining subgraphs?

I would like to have a function that removes an edge from a graph and returns all remaining graphs after the operation. For example for a graph like ...
0
votes
0answers
34 views

Removing numerical instability in plots of functions over large domains

suppose you have a large domain you wish to plot a function over, which depends on numerical values usually around or above you machine precision e.g. ...
2
votes
2answers
136 views

How do I define and plot a function involving random variable? [closed]

I am struggling to define and and plot the following function: $\qquad \sin(x) + 0.15\,u$ where u is a uniform random variable in the range [-1, 1]. How can I define such a function and then plot ...
0
votes
1answer
37 views

Finding the best representation of a numerically-inverted function via InterpolatingPolynomial and/or variations

Below is the routine I am using to sort of represent the numerically-inverted function $TP$. Basically I am finding a necessary interpolating polynomial $TPint$ that fits with the data points given by ...
6
votes
4answers
336 views

Iteratively strip off simply connected edges in graph?

Consider a set of edges composing a directed graph. For example: ...
0
votes
1answer
59 views

Is there a faster way to compute and resuse this pdf?

I'm trying to compute the pdf of a multivariate normal in mathematica. ...
6
votes
2answers
142 views

Finding $x$, the exponent of a $2^x$ when we need an specific output

Say we need a program Findx[n_Integer, m_Integer] where n is an integer from 1 to 9 and m is an integer from 1 to 1000. The output of the program is a number x, which is the exponent of 2 that ...
6
votes
2answers
129 views

Select connected subsets of integer pairs?

Given a list of integer pairs such as list = { {1,2},{1,3},{2,5},{1,5},{6,7},{6,9},{4,6} }; What is a quick way to separate the pairs into groups in which every ...
1
vote
1answer
42 views

Table of function derivative evaluation

I want to create a table with numerical values of a function derivative by using the following code: ...
0
votes
0answers
41 views

Proper implementation of numerically integrated function inside a differential equation

I have a numerically-inverted function TP which is then fed to the differential equation below. My question is: What is the right way to implement this ...
1
vote
2answers
45 views

Switch applying tests to forms

Is it correct that the Select equivalent of Cases is missing for Switch? I mean a function <...
12
votes
4answers
403 views

Renaming options of custom functions while preserving backwards compatibility

I have a package with many functions. There is an option name that several functions share. I feel that the current name of this option was not the best choice. I would like to rename it, but at the ...
0
votes
1answer
46 views

ListPlot with gradient

I have a dataset in which each element is a list of 3 numbers eg. data={{0,0,0},{1,2,0.7},{3,4,2.3},{3,4,3.3}} I'd like to make a 2 dimensional plot in this way: ...
7
votes
2answers
423 views

Can we make a faster Boole implementation?

I just learned about Mr. Wizard's very efficient code here. ...
2
votes
1answer
39 views

How to define a function that can transform integrands to the unit hypercube?

We know most integrands can easily be transformed to the unit hypercube: $$\int_{a_1}^{b_1}\cdots\int_{a_d}^{b_d}{\rm d}^{d}x\, f(\vec{x})=\int_0^1{\rm d}^dx\,f(\vec{x})\prod_{i=1}^{d}(b_i-a_i)\ ,$$ ...
2
votes
3answers
75 views

Globally Defining a Variable that Depends on Arguments of Functions [duplicate]

I have many delayed-defined functions of many variables, and all the functions share a term containing some of these variables. Thus, I would like to just call the term ...
5
votes
1answer
172 views

Pure function as a variable of another function

In a notebook, I have a function that basically needs to do something like calling a pure function within a function. I would say that what best describes would be an example like: ...
5
votes
5answers
300 views

Appending _?NumericQ automatically to every variable of a function in the definition [duplicate]

I have a list of expressions as follows: as=Table[a[k],{k,1,500}] I would like to append _?NumericQ to every element of this ...
6
votes
3answers
141 views
5
votes
1answer
166 views

Function[{u}, g[u]] vs. Function[u, g[u]] : In which the behavior between differs?

Function[{u}, g[u]] Function[u, g[u]] The documentation lists both variants without specifying the difference. Does the behavior differ in some circumstances?
1
vote
1answer
72 views

Combine single pulse with Boolean test, and integrate series

I have edited this to include integration: This is a more general case of this question. I want to create a function that gives the integral of a series of single pulses of the form ...
0
votes
0answers
20 views

Define a function using pattern matching and repeated replacement to sum the elements of a list.(exercise in Paul Wellin's Book)

I am reading Paul Wellin "Essentials of Programming in Mathematica". I have a question about his answer to 4.1 Exercise 5. 4.1 Exercise 5: Define a function using pattern matching and repeated ...
0
votes
0answers
43 views

Representing an interpolating function

I just want to figure out how to "represent" or to inject an interpolating function into a numerical calculation. So, suppose i have an interpolating function $int$ and then i want to use NDSolve or ...
3
votes
2answers
74 views

Converting a free variable in a pure function into a parameter that can be varied under iteration

Here I am going, as a matter of illustration, make a large string list: l = Characters[WordList[]]; l = Table[DeleteDuplicates[l[[i]]], {i, Length[l]}]; This ...
0
votes
1answer
57 views

Equation of motion of a system

I am studying the problem in Vibration effects. I would like to obtain the simplified equation of motion in (2.7). ...
2
votes
1answer
50 views

Creating a bound method (partial function application)

I want to bind arguments to methods (e.g. for use in OOP creating a bound method--what Java just calls a method). I realized this is basically just a partial function application. Now I want to make ...
1
vote
2answers
44 views

Define a bilinear function of strings

I have a linear combinations of strings, e.g. combStrings = 0.1 "a" + 0.2 "b" I want to define a function f[] which deals ...
0
votes
0answers
52 views

Constructing a user function with an integral

Maybe this is a basic task to perform but I haven't found any literature. I am performing a convolution of two functions: ...
3
votes
2answers
223 views

How do I find a function to fit these criteria?

I want to find a smooth continuous function f[x] that satisfies the following for real values of x: ...
0
votes
0answers
71 views

How can I get a numerical value from a function?

I am a Mathematica beginner working on a problem in the area of quantum mechanics. I adapted this source code to work with the problem I'm trying to solve. At present, the graphics produced by the ...
0
votes
0answers
46 views

Force a function to be real

I have a multivariable function in Mathematica that arises as an eigenvalue of a matrix. It involves square roots of the variables involved, but Mathematica automatically assumes such a function to be ...
1
vote
1answer
46 views

How do I define a function that uses a recurrence relation? [duplicate]

I know how to define functions other than the ones that use a recurrence relation to calculate the $n$-th term of a sequence. How would such a function be constructed?
3
votes
1answer
127 views

Newton's Method

Problem statement: I'm currently new to Mathematica and have been trying to solve this problem. I was digging around and found this code: ...
3
votes
1answer
109 views

Force a function to report argument type mismatches

As a relative newcomer to Mathematica, I am still frequently caught out by coding errors that, at least by default, MMA does not indicate to the front end, in particular when I define a function and ...
3
votes
1answer
58 views

How to create a function that eliminates repeated elements

I want to create a function that eliminates repeated elements from a list without changing the order. For example: ...
0
votes
2answers
77 views

Continuous summation of a function [closed]

I have a simple function: func =x Sin[π x]^2 This creates a curve that oscillates between 0 and values that increase linearly ...
1
vote
1answer
64 views

Procedural Function not evaluating

I have this function (Nhfunction) defined as procedural: ...
2
votes
1answer
38 views