# Minimization problem using FindMinimum. Functional value “is not a real number”? [closed]

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 :

ClearAll[fn];
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?

-
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

## 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.

    ClearAll[fn];
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} /.
Last[NMinimize[
fn[{v1, v2, v3, v4, v5, v6}], {v1, v2, v3, v4, v5, v6}]]


results in:

{3.00983*10^-6,-2.99357*10^-6,-2.9875*10^-6,-3.01569*10^-6,-3.08566*10^-6,2.9084*10^-6}


and

{v1,v2,v3,v4,v5,v6}/.Last[FindMinimum[fn[{v1,v2,v3,v4,v5,v6}],
{{v1,0},{v2,1},{v3,0.8},{v4,0.2},{v5,0},{v6,-1}}]]


in

 {3.00791*10^-6,-3.00154*10^-6,-2.99627*10^-6,-3.01435*10^-6,-3.08366*10^-6,2.91801*10^-6}

-
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