Questions tagged [functions]
Questions about the use of built-in Mathematica functions, including pure functions.
3,781
questions
0
votes
1
answer
72
views
NestWhile with input as a list [closed]
I'm wondering how I can use NestWhile if my input is a list:
NestWhile[function,{1,2,3,4},...]
For example, I want ...
1
vote
1
answer
48
views
Filter out terms that include any combination of F[X] and G[-X]
I have the following problem which is closely linked to a previous question I asked some time ago (Replacement rule for terms that are separated by operators?).
In this specific instance, suppose I ...
0
votes
1
answer
67
views
Calling a function with a vector doesn't work for me
I'm trying to create a simple function that generates a transformation matrix from the partial derivatives of two coordinate systems. It currently works when I have it written like this:
...
4
votes
2
answers
608
views
Plotting 3D energy bands
I'm having a problem trying to plot a 3D energy band structure. Having a function of 3 variables (energy) for example:
f[x_,y_,z_]:= Cos[x]+Cos[y]+Cos[z]
What i ...
1
vote
1
answer
108
views
How to define a function having many steps? [duplicate]
I can't transform a simple code into a function. The function should take an integer and return a list of digits in a factorial number system:
...
1
vote
1
answer
105
views
Defining a function with For loop within For loop
h[n_] := For[i = 1, i <= n, i++,
For[j = 1, j <= n, j++,
g = g + i*j]; f = f + g;];
h[10]
I want to define a function to calculate the Sum from i ...
2
votes
2
answers
926
views
Find peaks, max and min of an interpolation function?
I'm new in mathematica.
I have a list of values and i don't know how to find some poitns, such as peaks, the max and min of an interpolation function.
...
3
votes
0
answers
198
views
How to call an old build-in function in a new version of Mathematica?
In order to use the UnitStep of Mathematica 5.2, I have to install two different versions 5.2 and 11.3 at the same time because ...
0
votes
1
answer
92
views
Why does the FindFormula result contain Abs in result?
If you look at the first example of FindFormula, why is the result Mathematica produces showing an Abs?
Table[{x, N[x Sin[x]]}, {x, 0, 4, .3}]
FindFormula[%, x]
...
2
votes
1
answer
74
views
How to fix label position inside Manipulate?
I'm trying to make this manipulation.
Initially, I use Text to add Happy Wedding. However, the function doesn't allow me to ...
0
votes
1
answer
310
views
How to ask Mathematica to express variables in terms of each other in an implicit function
How to ask Mathematica to give $y$ in terms of $x$ in this function? Is there a way to obtain a closed form expression for $y$ in terms of $x$?
$x=\frac{\left(y^4-1\right) \left(\coth (2 y)-\frac{1}{...
0
votes
1
answer
117
views
error for NMinimize with Parameters in the form f[a_]:=NMinimize
I'm trying to write a function of a variable as the argument of a minimization where that variable comes to play.
Here is the code :
...
0
votes
0
answers
71
views
Creating a special product function
I am having trouble working with lists inside functions with Mathematica. Basically, I have a list of numbers and a special way to multiply them. I want to have a function that is able to create a ...
1
vote
1
answer
1k
views
Define Function explicitely with List as argument [duplicate]
Background
There are multiple ways to define Functions. I would assume all methods are equivalent, and allow for the same options. However, I fail to find the ...
0
votes
1
answer
48
views
Order of evaluation of variable
I'd like to control the order of evaluation in a multi-variable function.
Example: Suppose I have the function:
B[x_, y_] := x + y/x;
If I try to evaluate ...
1
vote
0
answers
240
views
Get R^2 value between interpolating functions and a list of points
I am looking to compare the degree of accuracy of a theoretical model by comparing my theoretical curve to my experimental data points.
My theoretical curve is an interpolating function generated ...
2
votes
1
answer
50
views
Use a list with single number for the second input of Table
As you see both inputs below give the same results.
Is there any reason to use List[3] instead of just 3 in the first case?
<...
3
votes
2
answers
125
views
When do functions apply on lists and when they do not
I have read in my lecture notes on Mathematica that functions (in the general sense) can be applied to lists of data and that they can return new lists with data. I have tried this and I have got ...
0
votes
1
answer
181
views
Derivative of function with large number of arguments
I have a function which depends on more than 30 parameters and I want to symbolically compute the derivatives with respect to the individual parameters.
From the documentation of the ...
1
vote
1
answer
41
views
I've been try to plot this function but it's not work. It's in the body [closed]
Plot[z^7 - 5*z^4 + 3*z^2 + 6*z - 4, {z, -2 - 2*I, 2 + 2*I}]
2
votes
0
answers
172
views
FindFormula: can I change the standard TargetFunctions?
FindFormula seems to have a limited number of TargetFunctions:
Possible functions for TargetFunctions are Plus, Times, Power, Sin,
Cos, Tan, Cot, Log, Sqrt, Csc, Sec, Abs, and Exp.
Is it ...
8
votes
2
answers
622
views
return {} when the function is given {}
I have a function taking an array as argument and giving an output. However, sometimes my argument is {} (the empty array), then how can I get an output {} when my argument is {}? Actually, I want the ...
1
vote
1
answer
84
views
Generalization of code is slower than particular case
I wrote the following Mathematica module:
...
1
vote
1
answer
241
views
n derivatives on a function of n variables
I want to derive an expression with respect to each variable of a function $f: \mathbb R^n \rightarrow \mathbb R$. More precisely:
$\left(\prod_{i=1}^n\frac{\partial}{\partial_{x_i}}\right) g(f(x_1,...
2
votes
1
answer
42
views
Find the two least common positive values that divides both 40131 and 41405 [closed]
I'm completely new to mathematica, and got stuck on a question. If I needed to find the least 2 common dividers for 40131 and 41405, how would I code it?
What i want is:
Prime Factorization of ...
9
votes
2
answers
393
views
Using vtx[] instead of vtx
There're two ways to generate a random tree as 1 and 2 below. Both work fine here. So what's the reason to use vtx[] instead of ...
0
votes
0
answers
38
views
Mathematica Function Taxicab Numbers [duplicate]
I have spent days trying to compile this code and I cannot generate a list of taxicab numbers for the Hardy-Ramanujan Theory. Here is the module I wrote earlier:
...
1
vote
1
answer
327
views
Printing Values Within a Function
Below is a function to calculate the overlap between two gaussian functions.
...
1
vote
3
answers
278
views
Finding Closed form expressions for sums
I am working with the a problem where I need to compute some complicated sums, for which I first define the following inner product.
...
1
vote
1
answer
122
views
0
votes
2
answers
59
views
What are equations on mathematica and differences between these errors? [closed]
These are the three errors I was given. I so far wrote the code which was computing the polynomial interpolation but now I am asked to find those three norms:
norm error
mean norm error
maximal ...
2
votes
1
answer
54
views
FindInstance confused by CoprimeQ
For some reason when I type
FindInstance[a + b == c && CoprimeQ[a, b, c] == True, {a, b, c}, Integers]
Mathematica just immediately returns my input as ...
1
vote
0
answers
24
views
strange behaviour of Eigensystem and Eigenvectors [duplicate]
consider this:
...
0
votes
0
answers
50
views
Define a function including two solve solutions
I'm trying to combine the solutions coming from two NSolves and define a new function that I've to integrate.
Basically I've defined two ...
2
votes
1
answer
313
views
Quadratic form for specific formula as matrix reprezentation [closed]
So I have problem for specific formula to create Quadratic_form form from $$y = 3 + x_1 - 2 x_4 + 2 x_3 x_4 + x_2 (-x_3 + x_4) $$ as matrix
\begin{bmatrix}
1 & 0 & 0 & 0 \\
...
1
vote
1
answer
121
views
Contour Plot not taking previously defined expressions?
I am new to Mathematica so my question might sound a bit silly, but I hope you help me.
While learning ContourPlot, I have learned that when I use the previously ...
3
votes
2
answers
181
views
How to get the nth value of a function with arbitrary number of arguments
I know that I can define a function of a List and get the nth argument like:
f[x_List]:=x[[1]]+x[[2]]
What if the argument of ...
12
votes
2
answers
242
views
The use of SlotSequence in If[#1 > #2, ##] &
The below function when applied to a list of two elements, will output the maximum between the two:
If[#1 > #2, ##] &
For example:
...
0
votes
3
answers
106
views
At how many of these points is f(x,y) (strictly) greater than both g(x,y) and h(x,y)? and
I try too find out the solution but is not work. Please help!
This what I wrote:
4
votes
1
answer
360
views
Real and imaginary parts of complex logarithm
I need to obtain the real and imaginary parts of the below expression with Mathematica:
$(- i a - m^2) \ln(\frac{i m^2}{2 a})$,
where $a$ and $m$ are real.
So we have:
...
0
votes
1
answer
1k
views
Plotting a Wavefunction [closed]
I am trying to plot a wavefunction for a 1D Particle in a box. I attached my code below, when I run it, it shows a plot with no lines on it. I am new to mathematica, so I am not sure what I am doing ...
-1
votes
1
answer
58
views
What is the problem in this program? [closed]
The output is showing running only.
For[m = 0, m < 0.05, m++,
For[a = 5, a < 20, a + 1,
a1 = a*(a/2);
x[m] = a1
];
];
2
votes
2
answers
804
views
How to convert list of variables x1, x2, x3 ,x4 ... x10 to list of x1_,x2_,x3_..x10_?
I'm writing a function where I need to give many inputs. I created a list of variables from Table function.
My aim is to get
...
3
votes
2
answers
180
views
Is there any command similar to Delaunay of matlab?
After finding this webpage where they mention the generation of land using matlab,
In its section how it works, explain its operation in detail,
I started trying to do it in MMA but I am doubtful of ...
1
vote
3
answers
296
views
How would I plot the inequality lines together with the intersection plot of the inequalities?
For example, I've got the following code:
Plot[{x >= 5, y >= 8, x + 2y <= 64, x + y <= 40}]
This would plot:
Now, this is fair enough. It shows me ...
0
votes
1
answer
57
views
For different value of input module is giving same result
I have a simple module written to extract a certain shape for a certain value of ω, but I am getting the same result for different input values into the module.
1.mode[1] and mode[2] looks exactly ...
1
vote
0
answers
45
views
How to speed up the evaluation of a sum of incomplete Gamma functions?
We need to do a ContourPlot for the following function $H[x,y,n]$:
...
1
vote
1
answer
2k
views
Unit Step Function [closed]
I will like to plot the unit step function of common function
, For example f(t)=H(t-4)t or f(t)=H(t-4)t^2
I have search through the Help Menu but cant really get a lead to the plotting. Thank you
2
votes
1
answer
38
views
How to use a list as a part of arguments for a function?
I have a function, say f[x,y,z] and a list l={b,c}. What is a more concise way to write
...
0
votes
1
answer
361
views
Properly defining and plotting a function that requires `NSolve`
I want to defined a function that solves some equation numerically:
...