Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.7K Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Integrate vs NIntegrate

Posted 10 years ago

Why do Integrate and NIntegrate give different values for the same integral ???

In[7]:= Integrate[
  Exp[(Cos[\[Pi] x] - 1)/(2 \[Pi])] Cos[6*\[Pi]*x], {x, 0, 1}] // N

Out[7]= -3.97146*10^-10

In[8]:= NIntegrate[
 Exp[(Cos[\[Pi] x] - 1)/(2 \[Pi])] Cos[6*\[Pi]*x], {x, 0, 1}]

Out[8]= 3.01079*10^-10
POSTED BY: Imran Khan
2 Replies

The two results are very close to each other. If you calculate

a = Integrate[
   Exp[(Cos[\[Pi] x] - 1)/(2 \[Pi])] Cos[6*\[Pi]*x], {x, 0, 1}];
N[a]
N[a, 16]

you will see somewhat different results. This is probably due to the different methods used by N[a] and N[a,16]. I understand that N[a] uses machine precision from the start, and the precision can degrade quite a bit. N[a,16] imposes that the end result has 16 accurate digits, and chooses the starting precision for that goal. It seems that NIntegrate in this case is more precise than N[Integrate] at machine precision.

POSTED BY: Gianluca Gorni
Posted 10 years ago

Thanks a lot. Yes, you are right. I was confused by the negative and positive signs. But , when I quit local kernel (or restart mathematica) and Evaluate the two integrals then Integrate and NIntegrate give the same the same value.

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