I'm having minor issues with the FindMinimum
function when using NIntegrate
inside. The functions work perfectly well but I get warning messages and I was wondering if maybe I could be enlightened on the correct usage of these two functions together.
For the sake of illustration I provide the full set of functions I used on a simple example.
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;
FindMinimum[
NIntegrate[(h*beta[t, 0, h] - h*beta[t, n, h] +
a.Table[alpha[t, i, h], {i, 1, n - 1}] +
b.Table[h*beta[t, i, h], {i, 1, n - 1}])^2, {t, 0,
T}], {{a, {0.76}}, {b, {0.4}}}, Method -> "ConjugateGradient"]
I get the following warning message :
NIntegrate::inumr: "The integrand (a.{(8 Piecewise[{<<2>>},0])/\[Pi]^3+(8 Piecewise[{<<2>>},0])/\[Pi]^3}+b.{1/2\\[Pi]\(8\Power[<<2>>]\Piecewise[<<2>>]+8\Power[<<2>>]\Piecewise[<<2>>])}-1/2\\[Pi]\((8 Piecewise[{{<<2>>},{<<2>>}},0])/\[Pi]^3+(8 Piecewise[{{<<2>>},{<<2>>}},0])/\[Pi]^3)+1/2\\[Pi]\((8 Piecewise[{{<<2>>},{<<2>>}},0])/\[Pi]^3+(8 Piecewise[{{<<2>>},{<<2>>}},0])/\[Pi]^3))^2 has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,3.14159}}"
I ask about this because FindMinimum
takes unexpectedly long time to converge to the solution (which is a right one). But I thought that maybe using the functions correctly will accelerate the process.
phi[t__?NumericQ,..]
and so on for all arguments. $\endgroup$a.Table[alpha[t, i, h], {i, 1, n - 1}]
isn't the best way to go here. $\endgroup$