Message Boards Message Boards

0
|
2870 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

numeric computation of maxima of a function

Posted 10 years ago
I have a matrix that depends on one variable and I want to maximize the sum of the first two eigenvalues. I wrote the following mathematica code:
Clear[T, f, x]
T[x_] := {{0, 1, 1, 1}, {1, 0, Exp[I*x], 1}, {1, Exp[-I*x], 0, 1}, {1,
    1, 1, 0}}
f[x_] := Sum[Sort[Re[Eigenvalues[T[x]]], Greater][[n]], {n, 1, 2}]
Plot[f[x], {x, 0, 2 Pi}]
NArgMax[{f[x], 0 < x < 2 Pi}, x]
NMaxValue[{f[x], 0 < x < 2 Pi}, x]
A little algebra shows that the maximum of this function is attained at x=Pi where f(Pi)=1+Sqrt[5], this also agrees with the plot. However, the values that NArgMax finds is x=1.5708 (=Pi/2) and NMaxValue finds 1.70928. So Mathematica is clearly not doing what I expect it to do. What am I missing/ misunderstanding? Thanks.
Note that the eigenvalues of the matrix are all real for real x, I put in the Re because otherwise Mathematica will complain that f is not real valued due to numerical inaccuracies.
POSTED BY: ralf rueckriemen
 In[1]:= t[
   x_] := {{0, 1, 1, 1}, {1, 0, Exp[I*x], 1}, {1, Exp[-I*x], 0, 1}, {1,
     1, 1, 0}}
 
 In[7]:= f[x_?NumberQ] :=
  Sum[Sort[Re[Eigenvalues[t[x]]], Greater][[n]], {n, 1, 2}]
 
 In[10]:= FindMaximum[{f[x], 0 <= x <= 2 \[Pi]}, x]
 
Out[10]= {3.23607, {x -> 3.14158}}
POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract