Message Boards Message Boards

Application of integration to a continuous list (xi,yi) of numbers; see nb.

In the attached nb. is an illustration of numerical integration. I have an error in the syntax; can someone help me find it.

thanks

Attachments:
4 Replies

Decided to try an experiment

In[1]:= f[x_] = Sin[x]*Sin[3 x];

In[10]:= NIntegrate[f[x], {x, 0, 10}]

Out[10]= 0.135097

In[12]:= pts = Sort[RandomReal[{0, 10}, 100]];

In[14]:= data = Table[{pts[[i]], f[pts[[i]]]}, {i, 100}];

In[21]:= i[n_] := Interpolation[data, InterpolationOrder -> n]

In[24]:= Off[InterpolatingFunction::dmvali]

In[25]:= Table[Integrate[i[n][x], {x, 0, 10}], {n, 0, 3}]

Out[25]= {0.154373, 0.0429017, 0.163184, 0.181286}
POSTED BY: Frank Kampas
Posted 9 years ago

Hi Luke, As Sean points out, integrating an interpolating function for experimental data is questionable. There is the issue of what the interpolation has done between the data points. One way to restrict this is to use InterpolationOrder->1 in the function to cause NIntegrate to be getting something close to a trapezoidal rule. But questions still remain. One way to eliminate all questions is to just execute a known rule. For example, the user-defined function below performs numerical integration by the trapezoidal rule. It assumes the data is a list of x-y pairs, and is sorted by increasing x values. But that's all. There is no question about added information.

Best regards, David

trapezoidal[list_] := Total@Table[
   (list[[n, 1]] - 
      list[[n - 1, 1]]) (list[[n - 1, 2]] + list[[n, 2]])/2,
   {n, 2, Length[list]}
   ]
POSTED BY: David Keith

Sean,

Thanks for the reply.

I'm trying to integrate "raw data" from an experiment and there are numerous raw data inputs. The data are A1's and they are converted to C1's which I'm manipulating to integrate.

luke

  1. In general, you do not want to symbolically integrate an interpolation of data points. This will probably work fine for your example, but please keep in mind this is not a good idea in general. It wouldn't be acceptable for published work.

  2. I strongly recommend that new users avoid using Subscript. Subscripts have different meanings in different contexts and are really ambiguous. I make this recommendation after having seen many many people like you in the past become very confused and frustrated with the ambiguity.

When you run into a problem like this, the first step is to create the smallest possible example which reproduces your problem. Here is a small example, like yours:

Table[Integrate[f[x], x], {x, 1, 1}]
Integrate::ilim: Invalid integration variable or limit(s) in 1. >>

The problem is that Table replaces all instances of x with 1. Resulting in this nonsensical code:

Integrate[f[1], 1]

I am not sure what you want to accomplish, otherwise I'd show you how to work around this problem.

POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract