I have a functional sequence whose general term is $a_n=x^n-x^{2\,n}$ where $x\in [0,1]$ and $n$ is a symbolic iterator index, which means $n$ is an arbitrary positive integer. When $n$ runs from 1 to an arbitrary large positive integer, it gives the sequence.
I want to get the maximum of the general term $a_n$ with respect to the variable $x$ where $x\in [0,1]$ but with $n$ being kept in place, which means the solution should be values containing numbers,and/or $n$ but no $x$, illustrating the maximum of $a_n$ for every possible $n$.
The algorithm is simple, for every possible $n$, $n$ can be regarded as a positive constant in the term, then we can solve for the null point of the derivatives of $a_n=x^n-x^{2\,n}$ with respect to $x$:
Solve[D[x^n - x^(2 n), x] == 0, x]
{{x -> 2^(-1/n)}}
And the maximum:
After examining the sign of the derivative, it can be determined {{x -> 2^(-1/n)}} is the point where the general term attains its maximum.
Simplify[(x^n - x^(2 n)) /. x -> 2^(-1/n), n >= 1]
1/4
Although I can calculate step by step like above, what I want now is a function which can automate this process. Preferably, the built-in function Maximize[]
since I have noticed:
Maximize[{x^\[Pi] - x^(2 \[Pi]), 0 <= x <= 1}, x]
{1/4, {x -> 2^(-1/[Pi])}}
where $\pi $ is a built-in constant greater than 1 and similar to $n$ in my sequence. However, when I try:
Maximize[{x^n - x^(2 n), 0 <= x <= 1}, x]
Maximize::infeas:"There are no values of {x} for which the constraints 0<=x<=1 are
satisfied and the objective function x^n-x^(2\n) is real-valued."
I guess it is because MMA does not know $n$ can be regarded as a constant for a specific step in my sequence, so I made those definitions below, intending to make $n$ just look like $\pi$ for MMA:
SetAttributes[n, Constant];
NumericQ[n] = True;
$Assumptions = n \[Element] Integers && n >= 1;
However, when I run the same code, it still gives:
Maximize::infeas:"There are no values of {x} for which the constraints 0<=x<=1 are
satisfied and the objective function x^n-x^(2\n) is real-valued."
My questions are:
1.Why Maximize[{x^\[Pi] - x^(2 \[Pi]), 0 <= x <= 1}, x]
works but Maximize[{x^n - x^(2 n), 0 <= x <= 1}, x]
fails even after I made those definitions?
2.How can I make MMA recognize in a specific scope that $n$ can be regarded as a positive integer constant and thus give me the correct answer {1/4, {x -> 2^(-1/n)}}
when I run Maximize[{x^n - x^(2 n), 0 <= x <= 1}, x]
?
3.Is there any other functions that can be somehow employed to automate the process and get the correct answer?
Thanks in advance.
Assuming[{0 <= x <= 1, n > 0}, sol = Solve[{D[x^n - x^(2 n), x] == 0, D[x^n - x^(2 n), {x, 2}] < 0}, x][[1]]; {x^n - x^(2 n) /. sol // Simplify, sol}]
$\endgroup$Maximize[]
and make it recognize n as a constant. $\endgroup$