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.

0
votes
0answers
13 views

Make traditional output for integrates [duplicate]

I want to perform a traditional output for integrates using a new function that I called HInt: ...
0
votes
1answer
31 views

Graphing the compound interest formula correctly

To preface, I'm very, very new to Mathematica. I've written a few functions to calculate compound dividends from stocks. ...
0
votes
0answers
25 views

Using `Format` to create a notation for derivatives

I want to create a new function that I called HD to give a visual way to see the derivatives. For example: The objective is apply the function ...
2
votes
1answer
30 views

Draw a graph and write its function based on the values and derivatives at different points?

This is a very general question since googling didn't bring anything useful up for me. Suppose that I have the value of a function at some points plus the derivatives at those points. Now I am looking ...
14
votes
4answers
1k views

Cleanest way to take a[b[c]] to a[b][c]

As indicated in the title I'm looking for the fastest way to transform a[b[c]] into a[b][c], and the natural generalization to ...
6
votes
2answers
67 views

Left-associative Apply

Often I want a version of @ that is left-associative (might not be using that term correctly). What I mean is I'd like some operator ...
0
votes
0answers
26 views

Change the attributes of the function `Format`

I think that the function Format has intrinsic an orderless attribute. So I've tried to create the following function: ...
0
votes
0answers
27 views

How to verify if all elements of a list are equal [duplicate]

I have a result in a list form: {1,2,3,4,5,6} How to verify if the elements are equal? If I use Equal doesn't works with a list....
1
vote
2answers
99 views

Creating a function that is a variant of Length [on hold]

I want to create a new function nLength that applies Lengthin each element from a list automatically. For example: I have a ...
2
votes
3answers
185 views

How to apply `Length` in all elements

I want to apply Length in each element from a list. For example: My list is: {1,{2,3},{4,5,6}} How to apply ...
0
votes
0answers
73 views

About creating my own fuction `ArrayQ`

I want to create my own function ArrayQ using Mathematica's functions as little as possible. I already have the "new" function that I called ...
2
votes
1answer
58 views

Creating my own function that mimics KeyFreeQ

I want to create my own function KeyFreeQ using Mathematica's functions as little as possible. For example: I already have my own function ...
5
votes
1answer
39 views

How to make Orthogonalize simplify each new vector before using it to orthogonalize the next one?

I'm trying to construct a set of orthogonal polynomials, starting from a specially-prepared initial polynomials: ...
4
votes
4answers
65 views

Get complete graph from set of vertices?

There is a function in Mathematica called CompleteGraph which takes a number and makes a complete graph with that number of vertices: ...
0
votes
0answers
21 views

Incorrect Function value and Derivative when expression in numerator yields zero

Recently I found that in special cases when the r.h.s. of a function definition is not simplified, and part of the expression in numerator yields zero, the value of the function is incorrectly zero as ...
0
votes
0answers
21 views

Strange behavior of BlankSequence and Apply

I would like to define a function with BlankSequence. Here is a simplified example. xPlusy[x_, y__]:= x + Plus @@ {y} Now I would like to try ...
3
votes
1answer
65 views

Trim graph to fully connected components?

Given a graph like e.g., ...
9
votes
1answer
214 views

Is it possible to restrict the arguments for a function to a specific entity type?

I'm trying to wrap my head around how to work with Mathematica for building (computable) domain specific knowledge. One particular thing I didn't quite understand is how to create symbols for ...
0
votes
1answer
25 views

Problem faced using user-defined mod function in loop

I want to make a program which tell whether a number perfect or not.So i tried like that: ...
1
vote
1answer
22 views

Obtaining non-null output from all parts of a compound expression

I've decided to post this question and self-answer, since this might be useful to others wishing to do the same thing. I was wondering how to obtain non-null output from all parts of a compound ...
6
votes
3answers
287 views

Calculating the width of the interval defined by an inequality

I am looking for a Mathematica function that takes an inequality as the input and gives back the width defined by upper bound - lower bound: Example: ...
0
votes
0answers
38 views

How a multilevel named slots can be written in one pure function [duplicate]

Learning mathematica now. Really curious how such a pure function should be written, i.e., an APIfunction that will return a dataset (TargetDataset) record from the string in a http request matching ...
1
vote
3answers
68 views

Creating a function that checks whether input is an integer (in the mathematical sense)

I am creating an alternative function of IntegerQ[] function. Now I don't want any output. I just want my function to check whether this is integer or not. I'm ...
0
votes
0answers
58 views

Implementing a function that exhibits linearity

I am trying to define a function $\mathbb{E}_t$ such that $\mathbb{E}_{t}[f[x_{s}]] = f[x_{s}]$ if s<=t, and $\mathbb{E}_{t}[f[x_{s}]] = \mathbb{E}_{t}[f[x_{s}]]$ if s>t. $\mathbb{E}_{t}$ is ...
0
votes
1answer
30 views
0
votes
0answers
34 views

Function that once called “erase” every other definition of my notebook

I encounter a really weird effect in Mathematica and I don't know what the wrong thing is nor how to correct it. I work with vectors of four components and I have a minimal set of definitions that I ...
3
votes
2answers
214 views

Outputting expressions in the order in which they're entered

Background For display purposes, I sometimes find it desirable to defeat Mathematica's canonical ordering of variables, and instead have it output terms in the order in which I type them. E.g., ...
2
votes
0answers
44 views

Fast way to check if an expression matches any of the rules in a list?

I have a function defined roughly like so. This is a minimum recreation. foo[expr_, rules: {__Rule}] := "some fancy result" /; AnyRuleMatchesQ[expr, rules]; What ...
8
votes
1answer
133 views

Element–wise summation for custom function

I use a custom function/head Operator[low, high] which encodes a generic polynomial expression split into "low" and "high" summands following considerations which are irrelevant to this question. Two ...
0
votes
2answers
46 views

Sum over integer partition with variable function argument

Define $$\hat{X}(Y) = [X,Y] $$ I have known matrices $S_i$ and $V$. I am trying to use Mathematica to define a function which calculates $$ \sum_{\substack{n_1, \ldots, n_k>1\\ n_1+\ldots n_k = ...
9
votes
1answer
175 views

Force evaluation of user-defined function

Consider a function that sorts its arguments based on a function called order ...
1
vote
2answers
52 views

Defining a function that treats input as two unordered lists

I have a function f2 I'd like to code into Mathematica with the property that it takes in two lists, treats those lists as unordered, and maps to a symbolic value. If I were instead using a function ...
0
votes
1answer
56 views

Defining a function with a point of finite discontinuity [closed]

I wrote the code for the function $T$ defined on $[0,1]$ by $T(x)=\frac{x+2}{3}$ if $x\neq\frac{1}{2}$ and $T(\frac{1}{2})=1$ as follows. ...
1
vote
3answers
65 views

How to write a discrete function which depends on pairity

Consider the following function for example $$ k = \sum_{n=0}^{\infty} \Gamma(\frac{n+1}{2}) y(n)$$ $$y(n)=\cases{2^{\frac{n}{2}} \text{ even}\\ 2^{\frac{n+1}{2}} \text{ odd}}$$ How can such function ...
3
votes
3answers
199 views

Work of a force field [closed]

I have a parameter curve in 3d: r1[t_] := {Cos[2 Pi t], Sin[2 Pi t], t} r2[t_] := {1, 0, t} r3[t_] := {1 - 1/2 Sin[Pi t], 0, 1/2 - Cos[Pi t]} with a vector field:...
5
votes
1answer
101 views

Defining multiple functions

I have a matrix with 4 elements that I want to turn into functions without explicitely defininig all the functions "by hand": ...
1
vote
2answers
74 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
341 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
41 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
30 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
79 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
92 views

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

Consider lists of vectors of elements like ...
0
votes
0answers
17 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
36 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
28 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
33 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
24 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
36 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. ...