I'm experiencing a problem using FindMaximum that I don't understand (due to my newbie knowledge of Mathematica's syntax). That is, FindMaximum sometimes returns a (correct) answer, but sometimes returns

The function value some number i is not a real number at {t} = {some number}.

I have two defined functions:

Envelope[t_, A_] := Norm[MatrixExp[(A) t]];

MaxEnvelope[A_, tmax_] := FindMaximum[{First@Envelope[t, A], 0 <= t <= tmax}, t];


For an example matrix that "works":

A1={{-1, 15}, {0, -10}}
MaxEnvelope[A1, 5]


{1.40801, {t -> 0.212153}}

which makes sense given the plot

Plot[Envelope[t, A1], {t, 0, 5}]


For an example matrix that throws the error:

A2={{-0.293578, -0.880734}, {0.0103211, -0.344037}}


FindMaximum::nrnum: "The function value -1.+4.54871*10^-9\ I is not a real number at {t} = {6.06351*10^-9}. "

There is clearly a maximum here though:

Plot[Envelope[t, A2], {t, 0, 5}]

The problem appears to be the { } that wrap t and what is clearly a real number. But why does the first matrix work and the second one not?

  • $\begingroup$ I don't think the problem is the {}. It's the non-zero imaginary part of the function value (hence it is not real). $\endgroup$
    – Michael E2
    Dec 12, 2015 at 20:30
  • 1
    $\begingroup$ Try Clear[Envelope]; Envelope[t_?NumericQ, A_] := Norm[MatrixExp[(A) t]]; $\endgroup$
    – Michael E2
    Dec 12, 2015 at 20:43
  • 1
    $\begingroup$ That worked! Thank you very much. $\endgroup$
    – user12734
    Dec 13, 2015 at 4:39

1 Answer 1


Using ?NumericQ to control evaluation fixes the problem. The reason is somewhat subtler than usual and is discussed below. I also removed the First from MaxEnvelope; it seemed to me to be a left-over from the OP trying to deal with the problem.

Envelope[t_?NumericQ, A_?(MatrixQ[#, NumericQ] &)] := Norm[MatrixExp[(A) t]];

MaxEnvelope[A_, tmax_] := FindMaximum[{Envelope[t, A], 0 <= t <= tmax}, t];

A2 = {{-0.293578, -0.880734}, {0.0103211, -0.344037}};
MaxEnvelope[A2, 5]

(*  {1.15797, {t -> 2.06801}}  *)

The use of ?NumericQ is discussed in What are the most common pitfalls awaiting new users? Here the reason it works is somewhat different than the usual reasons that one needs to control evaluation.

The problem comes from round-off error in evaluating Norm on a symbolic matrix with approximate coefficients. First, a matrix with a symbol t:

Norm[MatrixExp[(A2) t]] /. t -> 1.

Max::nord: Invalid comparison with 0.476429 -6.71157*10^-18 I attempted. >>
Max::nord: Invalid comparison with 1.1094 +1.19767*10^-17 I attempted. >>

(*  Max[0.476429 - 6.71157*10^-18 I, 1.1094 + 1.19767*10^-17 I]  *)

Next, with a completely numeric matrix:

Norm[MatrixExp[(A2) t] /. t -> 1.]
(*  1.1094  *)

If we inspect the result of Norm in the first example, we can see the problem. There are some small imaginary parts and some unevaluated Conjugate expressions (Short form shown):

 Norm[MatrixExp[(A2) t]]

Mathematica graphics

Evidently, Norm does some processing on the symbolic matrix and there is round-off error in computing the coefficients. When this complex-valued expression is passed to FindMaximum there are problems. (The First@Envelope[..] in the OP can be seen to pick out the first argument to the expression Max[..] returned by Norm.)

The fix, t_?NumericQ and A_?(MatrixQ[#, NumericQ] &), ensures that MatrixExp[(A) t] is a completely numeric matrix before passing it to Norm.

  • 1
    $\begingroup$ The problem is also demonstrated by SingularValueList[MatrixExp[A2 t], Tolerance -> 0] /. t -> 1.; since Norm[] is equivalent to taking the maximum of that, the OP's problem is seen. $\endgroup$ Dec 13, 2015 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.