Abnormal result of lambda_max function

lambda_max(matrix) = max(eig(matrix)) as advertised in the documentation and help for lambda_max. You will see this if you move the statement
beta = max([lambda_max(P*A1 + A1'*P) lambda_max(P*A2+A2'*P)])
to after cvx_end. When you do that, the “discrepancy” you described will go away, because the same value of P, i.e., the value returned by CVX, will be used in both cases.

In your program, beta is a CVX expression, which depends on the CVX variable P. I don’t know what value of P is used to evaluate the expression, beta, when the program is executed (it appears to be undocumented behavior, as it is something you shouldn’t be doing), but it winds up not being the “optimal” P returned by CVX, meaning in your case because there is no objective function, whatever feasible value of P is returned by the solver/CVX.

Or to put it more clearly, the value of a CVX expression after CVX has completed, appears to be undocumented behavior. And the value of that expression after CVX has completed is not necessarily the same as the value of that expression when evaluated using the values of CVX variables returned by CVX. Perhaps that could be made clearer in the CVX User’s Guide. But the Users’ Guide does state “An expression object, on the other hand, is initialized to zero, and should be thought of as a temporary place to store CVX expressions; it can be assigned to, freely re-assigned, and overwritten in a CVX specification.”