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 [functions]

Questions about the use of built-in Mathematica functions, including pure functions.

1
vote
1answer
24 views

How do I plot a function that contains variables I have previously defined?

I am trying to plot t as a function of the variable EE which is itself included in variables I have defined. However, when I ...
0
votes
0answers
20 views

Acquire a single-variable function by slicing a 3d graph along a given line

Consider my Calculus 2 math problem: Given a function f[x,y]=x^2-3xy and two vectors a = {1,2} and b = {1,1}. Spanning a linear ...
6
votes
2answers
235 views

How can I make assignments persist among sessions?

Yesterday, I imported a large set of data into a Mathematica notebook and stored each imported list of numbers in a function. For example, I would map a list like ...
3
votes
2answers
55 views

Rescaling RegionFunction in StreamPlot

I often use a version of @Rahul's myStreamPlot (original here) to make nice looking StreamPlots. Briefly, it rescales the axes ...
1
vote
0answers
22 views

Define an operator without chain rule

I am trying to define a linear operator myOp[f[x, t]], which commutes with linear differential operators without involving the chain rule, i.e., ...
1
vote
2answers
101 views

Computation with arrays of numbers

My code is m = RandomVariate[NormalDistribution[], 100]; c = 0.1; f1 = RandomVariate[NormalDistribution[], 100]; F = Sqrt[c]*m + Sqrt[1 - c]*f1; I would like to ...
0
votes
1answer
52 views

Simplifying nested pure functions

I have several functions: ...
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
32 views

Functions for multiple fonts [closed]

I'm looking to make a series of figures with various font types in them, but it's rather bulky code when I keep having to make each text the font/size it's supposed to be. Is there a way to get ...
2
votes
2answers
75 views

How to set up an function with increasing coefficients?

I'm trying to set something up with the end results of: sum = c1x^1 + c2 x^2 + c3 x^3 ... etc but I'm struggling to set up the increasing power while keeping the ...
4
votes
2answers
182 views

Find maximum of the output from reduce

I am trying to reduce a function in two variables($n_1$ and $n_2$) whose domain is the set of Integers. I get a long list of pairs of values for these two variables(instead of a range). This could be ...
5
votes
7answers
408 views

How to substitute values from a list into a function?

I was hoping to take pairs of numbers from a list and substitute them into a function. So if my list was list = {{1,2}, {3,4}, {5,6}} and my function was <...
4
votes
2answers
125 views

GeometricMean definition

According to the documentation for GeometricMean GeometricMean[Table[x[i],{i,1,n}]]==Product[x[i],{i,1,n}]^(1/n) Presumably ...
2
votes
0answers
67 views

How to prove subspaces of function spaces?

In teaching Linear Algebra, I would like to prove or disprove whether a nonempty subset of a vector space, is a subspace. For this, I would show that the subset is closed under both addition and ...
1
vote
1answer
33 views

Problem when using TrackedSymbols and UpdateInterval to refresh different expressions at different times inside Dynamic

While attempting to optimize my program, I noticed an issue with the Refresh expressions I am using inside a particular Dynamic[]. I will use a simplified example ...
1
vote
3answers
39 views

Using previously defined function in ColorFunction

I want to use a previously defined function as part of a function definition for ColorFunction. I tried the following and it worked: ...
0
votes
1answer
58 views

Find area under real part of complex curve without numerically integrating

I have a function defined within the domain 0<=x<=2*Pi. f = Cos[x] * (a - 1 - r*Cos[x])^1.5 on the domain: ArcCos[(a-1)/r] < x < 2*Pi-ArcCos[(a-1)/r] f = 0 elsewhere 'a' and 'r' are ...
1
vote
1answer
88 views

How do I draw a function along with a particular tangent line at a specific point? [duplicate]

I would like to draw a function (x/x^2+1), and at a certain point, i'd like to draw a dot along with the tangent line at that specific point. what I have tried is the following: ...
4
votes
1answer
47 views

Manipulate the effect of varying the level of flattening on a TreeForm expression

I want to visualize how Flatten works and have a slider that changes the level of flattening. Here is the list of lists I'm using and Flatten function. ...
0
votes
0answers
27 views

Manipulate and Graphing Multiple Functions on the same Axis [duplicate]

Can Anyone help me out graph both function and its tangent line on the same xy axes, please? ...
3
votes
3answers
151 views

How can I use a Module anonymously as the function for /@?

I've looked for a similar question but the one that came up first has no answer, so please bear with me as I am a complete newbie to Mathematica. My ultimate goal is to generate custom ticks for a ...
0
votes
1answer
35 views

FunctionDomain - Meaning of “True” in output and documentation

Can someone tell me the meaning of True in output when I use FunctionDomain please? I guess that the meaning of ...
10
votes
2answers
707 views

Define function that behaves almost identically to Mathematica function

Often I like to define my own functions that are almost exactly the same as Mathematica defined functions, apart from a few tweaks. See this question for example. I want to define them properly so ...
5
votes
2answers
64 views

Counting the number of unconnected subgraphs

If I have a Graph, how can I count how many disconnected pieces it has? Mathematica must know this since it is able to separate them out when it displays the graph, ...
1
vote
0answers
33 views

Generic symbols vs Generic functions arguments [closed]

I've got a lot recursion relation that takes multiple hours at a time to run. I'm looking for some subtle reasons why it takes so long, and hoping to be able to reduce the time it takes for the more ...
1
vote
1answer
26 views

How do I use the output of Range as the input arguments of another function? [duplicate]

If I enter LCM[1,2,3,4,5] 60 is returned. if I enter LCM[Range[5]] {1,2,3,4,5} is returned. I think I understand why it returns ...
2
votes
1answer
34 views

Computing the Multivariate Normal density gives sometimes different values from in-built function

I'm trying to define the density of the Multivariate Normal distribution, since it will be faster to compute for greater dimensions (vectors of size 50 or more), specially when I have to do those ...
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 <...
0
votes
1answer
49 views

Tag Set Delayed and D

I used the Tag Set Delayed to set F /: D[F[f_], x_] := F[D[f, x]] It works if I give as input a single F: ...
1
vote
1answer
42 views

Variational Operator in mathematica

I'm trying to do the following variational operation in Mathmatica and VariationalD command doesn't give me the correct answer. Is there any other command that I am unaware of ? $\delta (y'' * y) = \...
1
vote
1answer
68 views

Creating a diagonal matrix from from a vector [closed]

I try to create a function that create a diagonal matrix in which the diagonal are: $\qquad 1,a,a^2, \cdots,a^n,1,a,a^2, \cdots,a^n$ Here is my attempt: ...
0
votes
1answer
45 views

How can I build a function using subfunctions

I am trying to build a function in Mathematica. The function is quite long so I would like to define subfunctions and then build them in the final function. Something like f1(t),f2(t),f3(t).... the ...
10
votes
4answers
436 views

How do I apply something like the double slash notation but not at the end of line?

f[x_] = x^2; Scan[Print[f[#]] &, {1, 2, 3}] I want to do something like this, but I don't want to type so many brackets. I'd like to have something like <...
0
votes
0answers
29 views

To assign an array to a function

// Pre-defined parameter kS = 2*(\[Pi]*NefS)/LambdaSS; Here, NefS is a function of LambdaSS. The matrix m (i,j) defined corresponding value of NefS (jth ...
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 ...
8
votes
2answers
205 views

Finding the point closest to a parameteric curve produced by a numerical method

Question How can I find the closest point to a parametric curve produced by a numerical method. General Context I have a parametric curve (which I will call $g$) produced from a averaging many ...
1
vote
2answers
60 views

Different BoundaryStyle for different sides of a RegionPlot

How can one Define a function in the RegionPlot that gives different BoundaryStyle for different sides? I mean ...
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
1answer
53 views

Why is ww[[1]] not a valid variable in FindMinValue and Plot [closed]

Why is ww[[1]] not a valid variable when given to FindMinValue and Plot, but is a variable ...
1
vote
1answer
45 views

What is the best way to dynamically evaluate multiple function?

I have a notebook with a list of operation where the result of a function is the input of the following. Example: ...
11
votes
2answers
379 views

On random numbers extracted from NormalDistribution by two different methods under the same seed

I've encountered the following situation within various trials. Why does such a difference arise between bulk sampling and one-by-one sampling? ...
1
vote
1answer
63 views

Complex partial fraction expansion

I would like to have a tool for partial fraction expansion of polynomial quotient $$\frac{P(z)}{Q(z)},$$ where the order of the polynomial $P(z)$ is less than that of $Q(z)$. The output of the ...
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, ...
0
votes
0answers
27 views

How to automatically see user defined function arguments list?

Having typed a user-created function's name I would like to be able to see either the concise syntax dropdown available for inbuilt functions (shown below left) or alternatively to be able to see the ...
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
1answer
39 views

List as function argument [closed]

I have a problem when using a list as argument of a function. When I use only a single number, the result is OK but when I use a list, the result is wrong and I have this error message I can't ...