Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question is a follow-up of another one I asked a few days ago. I followed the instructions given in the answer provided by the user that responded. I modified that answer to solve another problem.

The issue now, is with FindMinimum claiming that the functional value is not a real number when evaluating.

What I intend to do, is to minimize the following functional $$v^T\mathbf A v$$

where $\mathbf A$ is a matrix calculated like this :

phi[t_, k_, h_] := (1/h)^3*
   Piecewise[{{(h (1 - k) + t)^2 (h (1 + 2 k) - 2 t), (k - 1) h <= t <= 
       k*h}, {(h (1 + k) - t)^2 (h (1 - 2 k) + 2 t), 
      k*h <= t <= (k + 1) h}}];
psi[t_, k_, h_] := (1/h)^3*
   Piecewise[{{(t - k*h) (h + t - k*h)^2, (k - 1) h <= t <= 
       k*h}, {(t - k*h) (h - t + k*h)^2, k *h <= t <= (k + 1)*h}}] ;
phipp[t_, k_, h_] := (1/h)^3*
   Piecewise[{{2 (h (1 + 2 k) - 2 t) - 8 (h (1 - k) + t), (k - 1) h <= 
       t <= k*h}, {-8 (h (1 + k) - t) + 2 (h (1 - 2 k) + 2 t), 
      k*h <= t <= (k + 1) h}}];
psipp[t_, k_, h_] := (1/h)^3*
   Piecewise[{{2 (-h k + t) + 4 (h - h k + t), (k - 1) h <= t <= 
       k*h}, {-4 (h + h k - t) + 2 (-h k + t), 
      k*h <= t <= (k + 1) h}}];
alpha[t_, k_, h_] := phi[t, k, h] + phipp[t, k, h];
beta[t_, k_, h_] := psi[t, k, h] + psipp[t, k, h];
T = Pi;
n = 2;
h = T/n;
petitAligne[t_] := 
  Table[## &[alpha[t, j, h], h*beta[t, j, h]], {i, 1}, {j, 0, n}];
petitAcolonne[t_] := Transpose@petitAligne[t];
A[t_] = petitAcolonne[t].petitAligne[t]; (*The A matrix*)

and $v$ is the vector I intend to minimize using FindMinimum. So I tried the following :

fn[ab_?(VectorQ[#, NumericQ] &)] := {ab}.Integrate[A[t], {t, 0, T}].ab;
FindMinimum[fn[ab], {ab, {0, 1, 0.8, 0.2, 0, -1}}, 
 Method -> {"ConjugateGradient", Method -> "PolakRibiere"}]

which returns the warning

FindMinimum::nrnum: "The function value {0.359283} is not a real number at {ab} = {{0.,1.,0.8,0.2,0.,-1.}}."

note that the value {0.359283} has no imaginary parts.

This optimization problem is the same as in the previous question, only written in another manner...

The correct answer is $$v=(0,\,1,\,1,\,0,\,0,\,-1)^T$$

What is wrong with this usage of FindMinimum?

share|improve this question
The "not a real number" question is asked at mathematica.stackexchange.com/questions/22359/nminimize-usage where some answers are available. –  whuber Apr 2 '13 at 12:52
@whuber Thanks for the info, although I already read through that thread. From it, I got an idea of what to try before asking my question and as you can see, the functional I'm using is convex and smooth as it is a quadratic form (I don't know of anything more convex). Also, I'm not trying global optimization as FindMinimum is for local optimization, constraining the problem was never the intention from the beginning. Maybe the answer to my questions are trivial, unfortunately I fail to see it... –  jrojasqu Apr 2 '13 at 13:28
I don't see that: your function is integrating a rank-1 tensor function of $t$ and that function involves an entire page of algebraic calculations. However, since you have pointed this out, I re-read the error message and find it's perfectly correct: "$\{0.359283\}$" obviously is not a real number; it's a list! It should now be evident how to fix up that particular issue. –  whuber Apr 2 '13 at 14:09
@whuber You're right... It all makes sense now... –  jrojasqu Apr 2 '13 at 14:19
@whuber yes, obviously the code is irrelevant and the message self-explanatory. This is why minimal examples are usually best... –  acl Apr 2 '13 at 14:51
add comment

closed as too localized by acl, whuber, m_goldberg, rm -rf Apr 2 '13 at 15:23

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 3 down vote accepted
    With[{int = Integrate[A[t], {t, 0, T}]}, 
      fn[{v1_?NumberQ, v2_?NumberQ, v3_?NumberQ, v4_?NumberQ, v5_?NumberQ,
          v6_?NumberQ}] := 
       First[{{v1, v2, v3, v4, v5, v6}}.int.{v1, v2, v3, v4, v5, v6}]];
    {v1, v2, v3, v4, v5, v6} /. 
   fn[{v1, v2, v3, v4, v5, v6}], {v1, v2, v3, v4, v5, v6}]]

results in:





share|improve this answer
Thanks for responding! Unfortunately there must be clearly something wrong with the way I set up the problem... –  jrojasqu Apr 2 '13 at 18:44
add comment

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