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
28 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
65 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
34 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
0answers
43 views

NIntegrate problems [on hold]

Sorry, I am boxed in by Mathematica again, every exit being blocked and can't find any answers on the web. This usually happens once the code is lengthy so it is hard to debug and to show with the ...
0
votes
1answer
45 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
82 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
61 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
63 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
66 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
65 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
100 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
35 views

Creating functions from a eigenvalues output [on hold]

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
162 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
27 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
51 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
44 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
25 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
43 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
30 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
92 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
47 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
45 views

Looping from a Set of Undetermined Size

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}$). ...
2
votes
1answer
50 views

How do I draw an angular vector field containing a domain wall?

Intuitively, an angular vector field $\theta(x)$ such as the following would describe a domain wall between two vortices/strings of opposite winding number. I would like to draw this on a computer ...
1
vote
1answer
57 views

Nested Do loops with externally defined iterators [closed]

I want to be able to define a set of iterators for nested Do loops, such as ...
4
votes
2answers
121 views

Simulating ndgrid function of MATLAB

I know that there has been an answer on meshgrid function of MATLAB. For functions involving more than 3 variables, this function does not work. In MATLAB, the ...
0
votes
2answers
60 views

Implementing the factorial rule

I want to implement a command in Mathematica in order to simplify factorials in the following way $$(n+x)!=(n+x)(n+x-1)\cdots n!$$ I started to build this up slowly. I have managed to implement $...
0
votes
1answer
33 views

Conditional Plot of a function if another function satisfies something and in the case of complex variable

Let's say we have function $g(\zeta)$ and another map $f(\zeta)$, where $\zeta$ is a complex variable. I am trying to plot a graph of $f(\zeta)$ but given the condition of $g(\zeta)$. For instance, ...
2
votes
1answer
32 views

A fast way to create a list with $A_i\cdot B_i^{-1}\cdot C_i$ in each component

Let us suppose I have to do the following computation $A_i\cdot B_i^{-1}\cdot C_i$, where $A_i,B_i,C_i$ are conformable matrices(dim=$50\times 50$). For that, I have 3 lists, each of size 1 by 10,000 ...
1
vote
1answer
36 views

Define Function using another Function and plot

I have a function defined by f[x_, y_] := 1/(x^2+1) + 1/(y^2+1); I can plot this function perfectly. Then I want to ...
2
votes
1answer
21 views

Applying pure function to rotate the label in a BoxWhiskerChart

Data is available from here https://www.ocr.org.uk/Images/400305-large-data-set-lds_1-h630-2018-h640-2018-2019-pre-release-data-mei.xlsx ...
5
votes
5answers
325 views

Replacing the Zeros of One List by the (i-1)th Element of Another List

My goal is to replace the zeros of one list with the (i-1)th element of a second list. For example, if list1 = {0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0} and <...
4
votes
4answers
247 views

How to “split” a function with two separate arguments of the form F[X][Y]?

I recently stumbled upon a function F[X][Y] that has two separate arguments X,Y. Note that it is not of the form F[X, Y]! So ...
3
votes
2answers
637 views

What is wrong with this procedural function to add numbers 1 through n? [closed]

I am trying to write a function to add numbers from 1 through h: function[h_]:= x=0; For[i=1, i=<h, i++, x = x + i]; Print[x] But I am getting some strange ...
3
votes
1answer
47 views

Is using Length more efficient than using === as stopping criterion?

I am using NestWhileList[ f[#, elems]&, pairs, Length[#1]<Length[#2]&, 2, Infinity, -1 ] to generate all suitable subsets from ...
3
votes
2answers
96 views

Convert defined variables to rule list

I'd like to make a function that takes a list of variables and returns a corresponding rule list with the current values of the variables. E.g. ...
0
votes
1answer
74 views

Finding the symbolic inverse of a function

Is there a way of inverting this function to obtain $r(\rho)$? ...
0
votes
0answers
20 views

How attribute a restrition for a variable inside a function

I have a function like this way: f[x_] := x + 2; In[148]:= f[b + 2] Out[148]= 4 + b How to impose a condition that the variable ...
0
votes
2answers
76 views

Generating a large sample of 10 x10 symmetric matrices

I am currently having some issues with Mathematica. I have a 10x10 symmetric matrix with the diagonal entries removed and labeled as "z". I now want to create a command that generates a sample of ...
1
vote
1answer
56 views

Modify the `Head`of a function [closed]

I created a function HIntthat gives me a traditional output for integrates. ...
1
vote
3answers
70 views

How to make functional rules not depend on an argument?

Consider the following: rule = f[x] -> Sin[x] if I now do, say: f[y] /. rule this does not work, because the rule wants ...
0
votes
0answers
21 views

Imposing conditions on argument for a function definition

Suppose that I wish to use "Piecewise" to merge two different interpolating functions (obtained via a NDSolve of some ODE), defined over negative and positive arguments respectively, like: ...
1
vote
1answer
42 views

Creating a function that performs a “`DotExpand`”

When you make a Dot[a,(a+b+c)] the output will be: a.(a + b + c) I want to make a function that expands the dot product, for ...
2
votes
2answers
89 views

Creating a function for a traditional output for integrates

I'm creating a function (HInt) for a traditional output for integrates. For example: HInt[f, x] If I specify just the domain, ...
4
votes
2answers
57 views

How to make FoldListIndexed ie FoldList with an index or iterator?

Is there a functional or inbuilt way to add an index to FoldList? i.e.: FoldListIndex[f,x,{a,b,...}] gives ...
4
votes
1answer
57 views

Construct a function with subindices

I'm constructing a function that gives me subindices in output. The function is HAt. For example: HAt[u == u0, t -> 0] ...
0
votes
1answer
60 views

Which built-in DistanceFunction options does Mathematica offer? [closed]

The documentation is not specific at all about which built-in distance functions are implemented in Mathematica: https://reference.wolfram.com/language/ref/DistanceFunction.html For instance, I ...
1
vote
2answers
100 views

Creating an Excel-Like Recursive Function

I'm trying to create a certain "excel-like" recursive function, which runs through a pre-defined list and performs an operation dependent upon the current position (similar to the "drag down" type ...
0
votes
0answers
25 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
76 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
31 views

Using `Format` to create a notation for derivatives [duplicate]

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