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
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
78 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
50 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
72 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
373 views

Nested optimization problem - Function approximation

I need to maximize the following function (the input to NMaximize below) ...
0
votes
1answer
65 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
58 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
103 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
51 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
30 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
44 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
78 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
114 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
37 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
223 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
48 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
112 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
113 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
185 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
102 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
64 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 ...
3
votes
1answer
51 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
147 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 ...
2
votes
1answer
46 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 ...
0
votes
0answers
35 views

piecewise function construction with two solutions for one variable

i would like to define function shown below: i try using ...
1
vote
0answers
160 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 bvp, there is solution given in output which is the solution from mathematica version 10.0.1. Output from above in mathematica 10.0.1 is, But when the similar ...
0
votes
0answers
36 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
3answers
66 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: ...
3
votes
3answers
127 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}+...
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: ...
1
vote
2answers
94 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 <...
7
votes
5answers
402 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 ...
0
votes
1answer
69 views

passing splice instructions

Consider some passing splice instructions using start,stop,step pattern ...
4
votes
1answer
81 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
46 views

Not respected assumptions

I' m writing a function with the following line: ...
1
vote
1answer
42 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:...
2
votes
2answers
96 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 ...
4
votes
4answers
264 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}$, $...
3
votes
2answers
104 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
65 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 ...
1
vote
0answers
46 views

Passing python data types as function arguments

I've a few python data types ...
0
votes
2answers
79 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}}

1
2
3 4 5
40