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
0answers
28 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 ...
1
vote
1answer
21 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: ...
3
votes
2answers
43 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
17 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: ...
0
votes
0answers
25 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}(...
7
votes
3answers
73 views

Make an InterpolatingFunction periodic

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

Right syntax to launch multiple kernels on SLURM cluster

Important: sometimes you may need to modify the kernel location. In my case I had to find the kernel location explicitly by executing which wolfram command in the ...
5
votes
0answers
169 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 ...
0
votes
2answers
105 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 ...
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
1answer
35 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,...
0
votes
0answers
36 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 ...
4
votes
2answers
83 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
30 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
53 views

Why some variables get substituted and others don't

I was running into some trouble with my math and I whittled it down to this nugget: ...
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
131 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 ...
0
votes
1answer
144 views

Automating a large operation by making a function

I would like to automate the following operation. To be transparent I shall put my code into separate chunks and explain the process. Suppose I have the following: ...
0
votes
0answers
34 views
2
votes
1answer
45 views

avoid use of a global variable

I am writing some piece of code to do some numerical integration by hand. To this end, I discretize the interval [0,1] on a grid $x_0=0,x_1,\dots,x_{Nmax-1},x_{Nmax}=1$ and compute the value of the ...
1
vote
0answers
91 views

General:: Exp[-717.401] is too small to represent as a normalized machine number; precision may be lost

I am solving pde. For the post processing below, there is solution given in output which is the solution from mathematica version 10.0.1. ...
0
votes
1answer
51 views

How to define a function through so that it has an integral of a fixed value?

I have a quite complex function of two-variables, let's say $\alpha(a,b)$ that has a parameter $c$ and I want to set this $c$ so that $\int_{-\infty}^{\infty} \alpha(a,b) \: \mathrm{d}a \: \mathrm{d}b ...
0
votes
0answers
34 views

How to define function in Mathematica

I have a 3 by 3 symbolic matrix M(x,y,z). Question:1 First, I want to find its eigenvalues and eigenvectors. After that I want to make each eigenvalue and eigenvector a function of x,y, and z i.e. <...
0
votes
2answers
64 views

How do I construct a matrix using table command. I can not form it's function

I have to form a matrix like this. How ever I can not directly input. I have to form a function and then use the table command. I am stuck. {{2,5,10},{9,12,17},{28,31,36}}
0
votes
3answers
60 views

NIntegrate with a function defined with conditions

Good afternoon, I am trying to integrate a function that is defined with a conditional. The simplified code is the following: ...
7
votes
5answers
391 views

How to speed up integers finding function?

Playing with integers I looked for a way of finding, let's say, $4$-digits positive integers such that $a,b,a+b$ had the same digits, like $$1089 + 8019 = 9108$$ I am a newbie and I used this function ...
3
votes
3answers
111 views

Equipotential surfaces using ParametricPlot

So I'm trying to plot lines on which the following function is a constant $$ \frac{\left(-\Sigma (r,0.99,\theta )+2 r^2-0.99^2 r \sin ^2(\theta )\right)^2}{\Delta (r,1,0.99) \Sigma (r,0.99,\theta )^3}+...
1
vote
1answer
55 views

expand function as power series of another function

Suppose I have a well-known function $f(x)$ and I want to know if this function can be expanded into power series of another function $g(x)$, like $f(x)=\sum_n a_n g^n(x)$, where $a_n$ is the ...
1
vote
2answers
88 views

Why can't Mathematica evaluate this integral?

I want to work with the rectangle function, which I define by f[x_, m_] := Limit[1/((2*(x - m))^(2*k) + 1), k -> Infinity]; (I know that in theory I can use <...
4
votes
1answer
78 views

Use a variable to represent another variable?

I'm trying to create a list of functions by replacing variables in a template. I tried this: ...
0
votes
1answer
45 views

Not respected assumptions

I' m writing a function with the following line: ...
4
votes
2answers
125 views

Plotting Basis Order function

Does anyone know how could I plot the basis order functions for the following function (code below)? An example of what I should expect is https://en.wikipedia.org/wiki/Lagrange_polynomial#/media/...
9
votes
3answers
351 views

How to create a version of FixedPointList for asymptotically periodic functions?

I need to efficiently generate a bunch of bifurcation diagrams. A simple familiar example illustrates the efficiency problems I'm running into: ...
2
votes
2answers
85 views

How to implement fast series multiplication

I need to generalize the SeriesData object for my own purposes. One of the things I need to do is to reimplement code to multiply product of series. I've made two ...
1
vote
1answer
38 views

How to list automorphisms on a finite set and analyze them

Let s be a finite set of integer lattice points, for example s = { {0,0} , {0,3} , {1,1} , {0,2} }. I am trying to do two things:...
3
votes
2answers
96 views

Putting “forbidden values” for functions

I am defining a function $f(x)$ and I would like to put undefined values to some $x$. The point is that if I plot the function I don't want an error to be returned, I want that for all the plotting ...
0
votes
1answer
58 views

Problem while running Mathematica code from Python using wolframclient library

This is a follow up to my previous post here I am trying to run a function from Python using wolframclient. The input arguments are passed from Python as Python ...
4
votes
4answers
261 views

NxN diagonal matrix with mixed zero and nonzero diagonal elements

I'd like to make a function that takes an odd integer N and returns a diagonal matrix A with the odd diagonal elements $A_{11}$, $A_{33}$, etc. equal to zero and the even diagonal elements $A_{22}$, $...
1
vote
0answers
43 views
10
votes
3answers
712 views

How to define a complicated function inside the body of Compile?

I want to compile a function in a way to keep its memory footprint down. In the example below, I am trying to compile a function f that makes three calls to ...
1
vote
2answers
78 views

How do I write a multivariate function? [closed]

I want to pass input arguments to a function In python I do, def solution3d(a, b, c, d): I looked at the documentation here https://reference.wolfram.com/language/...
3
votes
0answers
72 views
7
votes
2answers
135 views

Better way to rename arguments to a functional form so that duplicate arguments are sequentially enumerated

I need to modify expressions that such as f[w, w, a, y, x, a, x, a] into f[w1, w2, a1, y, x1, a2, x2, a3]. In short, I have ...
0
votes
1answer
42 views

Defined function keeps the variable

I'm a beginner at Mathematica, and I have a problem finding the roots of a function for a specific variable (using Jens' findAllRoots function). Due to the nature of my problem, I need to compute ...
2
votes
2answers
102 views

How can I fix my Simpson's rule integration code?

I was tasked with writing a function on Mathematica similar to NIntegrate, but that uses the Composite Simpson's Rule as its method for doing the calculation. The ...
2
votes
2answers
62 views

Normalized functions

I'm looking for a smart way to define normalized functions. I usually write f[x_] := f[x] = A Sin[x]/x; Then I integrate the function ...
0
votes
2answers
101 views

How to define some functions automatically?

I want to use Gauss-Seidel iteration to solve this problem. $$\left\{\begin{array}{l} 8 x_{1}-3 x_{2}+2 x_{3}=20 \\ 4 x_{1}+11 x_{2}-x_{3}=33 \\ 6 x_{1}+3 x_{2}+12 x_{3}=36 \end{array}\right.$$ ...
1
vote
1answer
44 views

Controlling Expansion of Functions

Suppose I had the following definitions const /: N[const] = 1 / Pi^2; f /: N[f[x_]] := const / x^2; g /: N[g[x_]] := Pi * Sqrt[f[x]] * x^2; Now for this example, ...

1
2 3 4 5
38