1
$\begingroup$

The actual expressions is quite complicated so I will use a trivial example.

Let

In[36]:= f[u_] := 1/3 - (5/18)*(Cos[u]*a[1] + Sin[u]*b[1])^2

Then

In[37]:= Integrate[f[u], {u, 0, 2*Pi}]

Out[37]= 1/18 \[Pi] (12 - 5 (a[1]^2 + b[1]^2))

In the actual situation I have complicated integrands of u like above multiplied by various combinations of a[i], b[i] (i=1,2,3). So, I have to perform numerical integration.

What I want is to "persuade" Mathematica to make the numerical integration without bothering that a[i], b[i] do not have numerical values. That is, I want somehow the output of

NIntegrate[f[u], {u, 0, 2*Pi}]

to be something like

2.0944 - 0.872665 a[1]^2 - 0.872665 b[1]^2

Is it possible to do so?

Thank you in advance.

$\endgroup$
4
$\begingroup$

This works on the simple example:

vars = Array[a, 1]~Join~Array[b, 1];
FromCoefficientRules[
 MapAt[
  NIntegrate[
    #,
    {u, 0, 2 Pi},
    AccuracyGoal -> 14] &,
  CoefficientRules[f[u], vars],
  {All, -1}],
 vars]
(*
  2.0944 - 0.872665 a[1]^2 - 1.3713*10^-17 a[1] b[1] - 0.872665 b[1]^2
*)

Chop[%]
(*
  2.0944 - 0.872665 a[1]^2 - 0.872665 b[1]^2
*)
$\endgroup$

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.