Assume I have the following parametrized curve:
trefoil[t_] := {Sin[t] + 2*Sin[2*t], Cos[t] - 2*Cos[2*t], -Sin[3*t]}; ...and two functions of the vectors $A,B\in\mathbb{R}^3$ defined via
integral1[A_, B_] := Sum[NIntegrate[ Sqrt[u1]*(Ai*Bj) /. {Ai -> A[[i]], Bj -> B[[j]]}, {u1, 0, 1}], {i, 1, 3}, {j, 1, 3}] integral2[A_, B_] := Sum[((Ai*Bj) /. {Ai -> A[[i]], Bj -> B[[j]]})*NIntegrate[Sqrt[u1], {u1, 0, 1}], {i,1, 3}, {j, 1, 3}] These two functions are very clearly identical; integral2 differs from integral1 by pulling the coefficients $A_i$ and $B_j$ out of the numerical integration. Upon trying to evaluate these functions at a random point along the above curve via:
integral1[trefoil[t3] - trefoil[t1], trefoil[t1] - trefoil[t2]] /. {t1 -> 0.1, t2 -> 0.2, t3 -> 0.7} integral2[trefoil[t3] - trefoil[t1], trefoil[t1] - trefoil[t2]] /. {t1 -> 0.1, t2 -> 0.2, t3 -> 0.7} ...I find that the first crashes with error messages concerning non-numerical values, while the second gives a value of -0.61606 with no issues.
My question: does anyone know why the evaluation of integral1 is failing and what I can do to fix my syntax here? I have a more complicated use case in mind, where I cannot pull the constants out of the integrand, but I think this example depicts the issue.
I think the HoldAll attribute is relevant here, but I cannot sort out a solution.
Really appreciate the help!