Stack Exchange Network

Stack Exchange network consists of 175 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
29 views

How to pass lists as arguments in NMinimize or FindMinimum?

The following code runs in Mathematica 12. But, I have two problems that I would like to solve: (1) How to pass a list as an argument to the function g in such a way that it can be used seamlessly ...
2
votes
1answer
20 views

CloudObject when defining functions - how to remove?

I'm an absolute idiot when it comes to Mathematica - I only use it for really basic things (because we use it as a graphic calculator in my high school class), so formatting will be less than ideal. ...
-2
votes
1answer
26 views
4
votes
1answer
56 views

ConstantDistribution

As far as I know, Mathematica lacks a definition for a probability distribution representing a constant random variable. Is this assertion correct? Is there a problem in making such a distribution ...
19
votes
2answers
345 views

Custom atomic expressions - modern tutorial

Atomic but sophisticated expressions are all around for a long time: Graph SparseArray. More are coming witch each new release,...
3
votes
1answer
91 views

Exponential generating function

I need to find the $m^\text{th}$ term for the following expression: $$ \left.\frac{\partial^m}{\partial t^m}e^{a t^2}\right|_{t=0}$$ I computed first few terms and used mathematica "...
1
vote
0answers
27 views

Make a function invariant under a permutation of the arguments

The output of my current notebook contains expressions that look as follows (V[{k,q},{s,t}] + V[{-k, -q}, {t,s}]) In my specific application these two functions ...
1
vote
1answer
38 views

Issues with negative sign in front of rules for Logarithm simplification

I declare a very simple rule. rule = -x_*Log[a_] :> x*Log[1/a] Now I give two expressions, -x Log[d] /. rule which ...
1
vote
0answers
44 views

How to simplify Log expressions using rules

I have the following expression, ...
1
vote
1answer
42 views

Function returning a pattern with condition - how to prevent condition to evaluate prematurely?

I figured it would be convenient to have a function that returns a pattern, that match equally nested brackets, of the specified type. Such a pattern is easy to create, but I get some error messages, ...
0
votes
1answer
47 views

Definition of complex conjugate?

I came across the following way of defining complex conjugate in mathematica [a]: SuperStar[y_] := y /. Complex[u_, v_] -> Complex[u, -v] I am able to ...
2
votes
1answer
60 views

Defining a function that has no return value

How can I define a function with no return value. For example, the Notation function from the Notation package seems to have no return value; I am looking to do the same thing for some of my custom ...
0
votes
1answer
39 views

Why is this NDSolveValue function remembering past inputs?

I have been attempting to generate a function that uses NDSolveValue to return the value of a solution to a system of ODE's when an event condition is triggered, as a function of the initial ...
0
votes
0answers
22 views

Redefining the inbuilt function and its derivative [duplicate]

I want to redefine the DiracDelta functions and its derivatives. I am successful at redefining the DiracDelta function but not ...
0
votes
0answers
53 views

Function for Probability of k Successes, Given Probability Vector [closed]

In an earlier post, @gwr provided the following function for a Poisson Binomial Distribution: ...
0
votes
0answers
22 views

Saving DownValues for a function computed in parallel

Is it possible to save DownValues of a function computed using a parallelization routine? I have a rather costly function f I wish to evaluate at a grid and save ...
0
votes
0answers
40 views

Why is this iterative process with matrix calculation so slow?

I am trying something similar to the following code with Ntime as large as 100 or so. Now it's very slow as shown by the Ntime=3 ...
0
votes
1answer
58 views

Memoization (or otherwise) for a recurrent definition of a (double) sequence of functions

Beside I've found answers to similar questions (e.g. this), I can't adapt them to my case. I am interested in the following sequence of functions $p_{m,n}(t)$, where $m$ and $n$ are integer: $$ \...
2
votes
1answer
37 views

User Implemented SHA-1 is failing for strings of length >512 bits

So, earlier, I posed a question regarding getting a user implemented SHA-1 hash function to work correctly. Well, I fixed the problems, cleaned it up a little bit, but now I have the problem for when ...
0
votes
0answers
51 views

Plotting the plastic zone — Tresca criterion

I've tried to plot the Tresca criterion from maximum shear stress theory. ...
11
votes
2answers
394 views
0
votes
1answer
45 views

Passing a function into another function that integrates the 1st function [closed]

for example I have a = Sin[t] and then I have f[a_] := Integrate[a, {x, 0, pi}] Will it work? Will the ...
2
votes
1answer
115 views

Analog of MATLAB's conv2 in Mathematica?

I have a matlab code filter = 1; F = conv2(double([1 2 1]),double([1 2 1]'))/16; for i=1:some_integer filter = conv2(double(filter),double(F)); end In the ...
3
votes
2answers
95 views

Append a function of an expression as operator form using Curry?

I fielded this q to tech support but didn't get a conclusive answer yet: Is it possible to use Curry specifically to modify ...
3
votes
3answers
106 views

Find non-case sensitive string in a mixed list of elements?

Consider an example list with mixed element types, e.g.: list = { 1.234 , a[2] , {"Abc" , 4/5} , "acb" }; I would like to have a function that finds the position ...
0
votes
5answers
74 views

Function of a function using variable list

My question is clarification for the question here Define function using variable list With doing this ...
3
votes
2answers
84 views

Overloading a function to pass in an expression rather that the name of a function

This is an example of procedural programming borrowed from Paul Wellin's book. It's a simple implementation of the Newton-Rhapson method. I overloaded the findRoot ...
2
votes
1answer
58 views

Composition vs Prefix @ [duplicate]

Whats the difference between Composition @* and prefix @? Composition[f,g,h][x] f@g@h[x] Functionally they both seem to give the same result.
2
votes
1answer
80 views

Using Condition (/;) for constructing big matrices [closed]

I want to construct a big matrix where the input of the matrix element is based on the relation between the row indices and column indices. Here's an example of what I tried but did not work: ...
0
votes
0answers
29 views

Having difficulties using results returned by Solve

I'm new to Mathematica, and I am still having some issues figuring out the general syntax. I've got to use Mathematica, as my research requires a powerful symbolic math program. I'm having trouble ...
2
votes
3answers
73 views

Indexed function recursion problem

I am trying to use indexed functions in a For loop; to illustrate, I give a trivial example. f[1, x_] := x^2 Now, I can define: ...
2
votes
1answer
36 views

Define different actions for the same operator depending on the nature of its arguments

I am working with terms of the form A**B1**B2 where A, B1, and ...
0
votes
1answer
51 views

Replace constant in summation function using replace or If or /

Hi i how do i replace constant for k in this summation. For following: Even 2*n Even replace k by a Even 2*n+1 Odd replace k by b Here is the code ...
2
votes
1answer
92 views

Defining an operator with given properties

In symbolic derivations with Mathematica, one often needs to define an operator with some desired properties, which will be used to stand for a general function or transform. For example, I would ...
0
votes
2answers
67 views

How to write a function of a polynomial

I will illustrate my problem with this example: I want to make a function which, given a polynomial, gives me the value of the integral $\int_0^1(ax+bx^2)dx=a/2+b/3$. Therefore, in this example, I ...
0
votes
0answers
64 views

Most efficient way to define evil and odious numbers [duplicate]

A positive integer $n$ is defined to be evil if the number of ones in its binary expansion is even, otherwise it is odious. Now define the function $$ \begin{equation*} t(n)= \begin{cases} 1 \rm{ \...
4
votes
2answers
71 views

ProbabilityDistribution with variable number of dimensions

I would like to construct a ProbabilityDistribution with a variable number of dimensions. I tried to use $Assumptions = x ∈ Vectors[d, Reals] so that the variable <...
2
votes
1answer
73 views

My version of PowerMod breaks down around 10^308

I have been trying to write a function that duplicates PowerMod[a, b, n], computing a^b mod n...
5
votes
1answer
102 views

Integrating function with /; in its definition

why f[x_ /; x>=0]:=x; Integrate[f[x] ,{x,0,2 Pi}] return unevaluated? Notice that the above definition of f[x] works OK ...
0
votes
1answer
44 views

Creating functions from a eigenvalues output [closed]

I need to create a function with the Eigenvalues output. The problem in question is that I need to manipulate variables from the eigenvalues and then plotting them. ...
3
votes
1answer
165 views

Table of Chebyshev psi function

This should be easy, but for some reason I'm struggling. The Chebyshev psi function is given as the sum from 0 to x of the von ...
0
votes
2answers
31 views

My function for computing a partial derivative generates an error message [closed]

Apologies, I'm still new at Mathematica. I have defined the function ...
1
vote
0answers
54 views

Making a function definition where the right hand side is evaluated before the definition is saved [closed]

My question is about assigning the resulting expression after evaluation of a function. So what I want: FOCf[x, y] := D[f[x, y], x] such it immediately ...
0
votes
0answers
48 views

Assigning values to variables inside Module using user defined function

Say I'm defining a function with some local variables, for which I'm using Module. Now, I want to assign some value (or perhaps a list of values or a list of list, ...
1
vote
0answers
26 views

Gauss elimination, reordering rows based on pivot values

I'm trying to create a code for Gauss elimination such that if there's a zero pivot during elimination, the equation will be reordered with the next row with a non-zero element and if it can't do that ...
2
votes
1answer
45 views

Another using Solve output for further calculations

I probably missed a question already posted as this topic seems common, but I looked at several, e.g. Using result of Solve in further calculations and am a little stuck. I didn't understand the use ...
3
votes
1answer
34 views

Defining a two variables function by Hessian Matrix

I need to define a function h by the Hessian matrix: f[x_, y_] := x^3 + y^2 h[x_, y_] := D[f[x, y], {{x, y}, 2}] and ...
2
votes
3answers
98 views

Writing a function with a domain that is a finite range of integers [closed]

I want to write a conditional function defined for $n=[-5:5]$. Explicitly, $\qquad Z_n=A e^{ikn}+Be^{-ikn}$ for $n\leq1$ and $Z_n=T e^{ikn}$ for $n\geq2$. I have written it but it is not very ...
1
vote
2answers
51 views

Replacement rule for terms that are separated by operators?

My main problem is how one can create a "transcending between operators rule" in the same term according to the minimal example bellow. Suppose I need to perform a replacement of the form ...
2
votes
1answer
46 views

Looping from a Set of Undetermined Size [closed]

For a problem I am working on, I need to create sets all the prime factors of a large set of integers (at least on the order of 1$-$1,000,000 but more on the order of all integers 1 to $10^{12}$). ...