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
0
votes
2answers
66 views

Mathematica ruins domain after explicit summation?

I'm working with this function ...
0
votes
1answer
45 views

Parallel evaluation produces wrong result

Consider the following code: ...
1
vote
0answers
30 views

rule generalization-NCA algebra [duplicate]

How can I generalize the rule ...
1
vote
1answer
46 views

How to define a numerical function which maps function to function?

For iterative numerical application (for example NestList) I need to define a function, which depends on a function and outputs a function. To describe the problem, here I give a simple example: <...
6
votes
1answer
66 views

Compile - Optimization of function calls - does it matter?

I was surprised to see that, in the results of CompilePrint for a function made with Compile, calls to ...
2
votes
2answers
178 views

Wolfram modules returning functions

I am trying to get a With / Module pair to return a set of functions. ...
2
votes
1answer
39 views

Downvalues for compiled functions

I'm a noob when it comes to DownValues, UpValues, OwnValues, etc. but I figured I would give ...
0
votes
1answer
44 views

Facing syntax difficulties when defining functions [closed]

Today is my first day using Mathematica to solve PDEs and ODEs. I have coded this block: ...
1
vote
1answer
38 views

Normal ordering of operators multiplied by scalars

I have the following code for normal ordering of two Boson operators $a(x),\,b(y)$: ...
1
vote
2answers
33 views

function changes upon condition

I have the function f[x_,y_]:=1/(Sin[x]+Sin[y]) which obviously becomes infinite for $x=\pi n, \;y=\pi n$ where $n\,\epsilon \, \mathbf{N}$. I want to give ...
0
votes
1answer
30 views

Why is a function just repeating input [closed]

This should give the answer of 2, but all it does is repeat the input. What is wrong? ...
8
votes
3answers
345 views

How to define a function reminding of names of the independent variables?

I am using a function with a lot of variables. There are 9 and sometimes more of them. In this case, it is difficult to memorize, which one stays on the, say, fourth position, and which one - on the ...
3
votes
1answer
86 views

How can I create a randomHop function that would return certain coordinates? [closed]

I've tried to create a function that's equal to a loop containing 4 if functions, one for each integer, but the result would not show the desired outcome. How can I go about doing this question? Write ...
1
vote
0answers
84 views

Do Loop contained in a function defined within a custom package doesn’t work as expected but works fine when function is defined directly in a script

Below is my code and I am having problems running the StdMPC function that I am trying to define. Running my code gives me the error that the matrix A and Xopt[[i]] are not of compatible shapes for ...
5
votes
1answer
142 views

Integral of a function defined with a loop

I have defined a function g as ...
7
votes
4answers
248 views

Unrolling a surface

The surface is determined by this parametric equation ParametricPlot3D[{Cos[θ],Sin[θ],z(2+ Cos[θ])},{θ,-Pi,Pi},{z,0,1}] How to unfold the surface in Mathematica? ...
1
vote
0answers
40 views

dot product of vectors with noncommutative elements

I came upon an interesting problem. Suppose you have three vectors $\psi=(a, b)$, $\phi=(c,d)$ such that their components do not commute: $ac\neq ca$, $bd \neq db$ etc. (in general the vectors may ...
0
votes
1answer
57 views

simplifying indefinite sums containing Kronecker Deltas

I want to simplify indefinite sums containing KroneckerDeltas, e.g: $\sum_{k,k1,q} \beta(q) \beta(k+k1+q) \delta(k1+q)= \sum_{k,q} \beta(k)\beta(q)$ where $k,k1,q \;\epsilon \; \mathrm{R}$ ...
1
vote
1answer
35 views

NonCommutativeMultiply syntax question

I define: ...
1
vote
2answers
71 views

How to simplify this sum of random waves?

Is there a way to simplify the random functions and their calls, in the code below? ...
2
votes
1answer
128 views

How to make this moving surface a continuous and derivable function?

I'm having troubles in defining a function of three variables: $t$, $x$, $y$, from a moving bumpy surface that should be derivable relative to its three variables. Here's the animated surface code, ...
1
vote
1answer
76 views

Randomly oscillating surface is not working well

I'm trying to built some random moving surface from a plane perturbed with random oscillators, and my current code isn't doing what I need yet, as seen from the ...
2
votes
1answer
49 views

How to insert variable height in this random bumps function?

I'm trying to insert a "time" variable that control the height of the random smooth bumps, but I'm yet unable to do it right, as shown with the code below: ...
3
votes
1answer
67 views

How to define a smooth function of random bumps in a plane?

I would like to define a simple function that gives random smooth bumps in a plane, a bit like the clumsy picture below, but it should be continuous: ...
3
votes
4answers
357 views

Nested optimization problem - Function approximation

I need to maximize the following function (the input to NMaximize below) ...
0
votes
1answer
64 views

Using conditions to construct a function [closed]

This is the hint my professor provided. We have 6 separate cases to define the function pow[x_ , r_]. The first case is where ...
1
vote
2answers
57 views

how to create a list of machine-made index names

How can I create such lists of variables: list1={sus1[t],sus2[t],sus3[t],...,sus99[t]}; list2={inf1[t],inf2[t],inf3[t],...,inf99[t]}; Consecutive ...
3
votes
3answers
102 views

Get a triangle’s angles from the sides

Hint: For the SSS case, you are given the 3 sides a, b, and c, and need to find the corresponding angles α, β, and γ. To find α, for example, you solve the equation ...
1
vote
1answer
49 views

Define a function for symbols with UpValues

Suppose that we define UpValues for different symbols isSpecialFunction[N1]^=True isSpecialFunction[N2]^=True isSpecialFunction[N3]^=True I would like to make the ...
1
vote
1answer
29 views

Define a derivative-like function

I would like to define a function Cd[a_][expr_] which takes an arbitrary argument a and acts on the expression ...
0
votes
1answer
43 views

Symbolic evaluation expressions containing a user-defined function [closed]

I have a function F[r] = (-1)^(r + 1) Binomial[n, r]/r I would like to evaluate F[x+1]/F[x] for some arbitrary ...
0
votes
2answers
70 views

Problems calculating scalar curvature of sphere

I'm not that great at using Mathematica so please bear with me. What I'm trying to do here is compute the coefficients of the metric tensor in 3D spherical coordinates, from which I'll construct the ...
3
votes
2answers
111 views

How to rescale a given interpolationfunction, thereby keeping the original name?

For a given Blackbox interpolation function f[x] examplary f = Interpolation[Table[{x, Cos[x]}, {x, 0, 2 Pi, 2 Pi/20}]] (*f[x]*) ...
1
vote
1answer
35 views

How to add noise to these random straight lines in 3D?

Here's a code that draws a pack of random straight lines in 3D: ...
2
votes
1answer
82 views

Parameter space search routine is too fast?

I wrote a small script to comb through the parameter space of a function looking for where the function satisfies a certain relation everywhere on its (co-ordinate space) domain. However, since I am ...
6
votes
2answers
221 views

How to generate randomly curved and twisted strings in 3D?

Here's a code that draws a set of random straight lines in 3D: ...
0
votes
1answer
38 views

How to define new random numbers in a table?

I'm trying to generate a plot of a few random straigth lines in 3D using the code below: ...
1
vote
1answer
46 views

Function that accepts functions and returns an expression containing their partial derivatives

I would like create a function that takes functions as input and includes different partial derivatives of the input functions, for simplicity's sake say: $\qquad m(f(x,y),g(x,y))=f_{xxx}(x,y)+g_{xyy}(...
8
votes
3answers
111 views

Make an InterpolatingFunction periodic

Interpolation can make an InterpolatingFunction periodic with the option ...
5
votes
1answer
32 views

How to duplicate UpValue of one function to another?

Let's say I have defined a function zO for the following up-values ...
0
votes
2answers
107 views

How do I integrate a For loop to generate iterations of the Sierpinski's Triangle?

I'm sorry if this is a basic question—I don't know anything about programming. I know you can create a graphic of Sierpinski's Triangle with a single command, but I'd like to know how to create one ...
0
votes
0answers
37 views

Purpose of seemingly repeated definition [duplicate]

This is related to the answer (link) of my previous question. The code works great. I just don't know what is the purpose of the additional part 'psi[n]' and 'psi[n]' in the definition. Thanks in ...
0
votes
1answer
37 views

evaluate an “implicit” function [duplicate]

I would like to know if it is possible to define a function for a function with an undefined variable, for example, f = a*x+b*y+c*z g[a_,b_,c_]:= f If I evaluate g,...
5
votes
0answers
179 views

Finding periodic cycles of a function

Given a function f[{x,y}] it is rather simple to use, for example, NSolve to find periodic points of period $n$. We simply take ...
4
votes
2answers
92 views

Function composition of function of several variables

Suppose I have the following function g[{x_, y_}, c0_, b_] := {x^2 + c0 - b*y, x} where b and ...
1
vote
1answer
34 views

Manipulate giving errors when I plot the product of a step function and a continuous function

Riemann's prime counting function J (link) takes half-values at every jump-discontinuity. So, I define it thus: ...
2
votes
1answer
29 views

How to conveniently evaluate a function at several points when there are way too many points

Say I define a function as follows: pos[n_] := If[Cos[288 ((n Pi)/233)] > 0 && Sin[288 ((n Pi)/233)] > 0, 1, 0] Then I want to evaluate at this ...
3
votes
1answer
63 views

Defining $f(x)=mx+b$ with $m,b$ separate versus `f[m_ ,b_ ,x_]:=mx+b`

Suppose I want to define a function $f(x)=mx+b$. And suppose I might want to change $m$ or $b$ later. Specifically, suppose I initially want $m=-2,b=10$, but maybe will change these values later Two ...
2
votes
1answer
47 views

How to convert a Piecewise function in a HeavisideTheta function?

I want to convert a Piecewise function in a HeavisideTheta function in order to correctly evaluate its derivatives at the point of abrupt change and then integrate the result along the axis. How can I ...
1
vote
4answers
138 views

How would we extract elements of a list greater than a certain value? [closed]

Say we have a list {35,210,67,950,32,365} how would we extract all the elements greater than 100 from this list (using a function)? The desired output would be ...

1
2 3 4 5
39