The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
1answer
52 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
23 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
37 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
50 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
61 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
38 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
66 views

Plotting the plastic zone — Tresca criterion

I've tried to plot the Tresca criterion from maximum shear stress theory. ...
11
votes
2answers
403 views

Strange behaviour of Check

...
0
votes
1answer
49 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
173 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
113 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
115 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 ...
1
vote
5answers
105 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
109 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
65 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
80 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
38 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
56 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
101 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
73 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
77 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
81 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
103 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
52 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
174 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
33 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
52 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
32 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
50 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
36 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
108 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
53 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
49 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}$). ...
2
votes
1answer
80 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
61 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
190 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
71 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
81 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
41 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
45 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 ...
3
votes
1answer
31 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
351 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
310 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
643 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
52 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
107 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. ...