### Precision for HW7 & 8

The MATLAB computation value for the integral is given as I = 32:121040688226245. With 'double' for all variables and %f in the printf statement, I only get up to 6 decimal places for the output. Is that sufficient?

**Moderator:** Dan Negrut

Hi Prof.Negrut,

The MATLAB computation value for the integral is given as I = 32:121040688226245. With 'double' for all variables and %f in the printf statement, I only get up to 6 decimal places for the output. Is that sufficient?

The MATLAB computation value for the integral is given as I = 32:121040688226245. With 'double' for all variables and %f in the printf statement, I only get up to 6 decimal places for the output. Is that sufficient?

Sounds good. It might as well be that your value is more accurate than MATLAB's, i don't recall off the top of my head what was the accuracy that i asked for when i had MATLAB approximate the integral.

One thing: please post here what you think to be the most accurate approximation that you got on your machine...

Have a good weekend,

Dan

One thing: please post here what you think to be the most accurate approximation that you got on your machine...

Have a good weekend,

Dan

Thank you, Professor. This is the value I got for the integral (using double for all variables): 32.121040

Abhirami,

please provide more digits (at least 12), you typically get in double precision 13 to 14 accurate digits.

Thank you,

Dan

please provide more digits (at least 12), you typically get in double precision 13 to 14 accurate digits.

Thank you,

Dan

With 'double' for all variables and %f in the printf statement, I only get up to 6 decimal places for the output. Should I try %ld in the printf maybe? What am I missing?

Thanks, Andrew Here's my answer: 32.1210406663595

The base line answer given in the handout is : 32.121040688226245

If I use trapz in matlab as an estimate I get (because I was not quite getting above):

Gives:

I = 32.1210406651714 where sizeof(f) = 1000001

which is close to the answer given in the hand out, but has 1 more (1000001) integral slice

Gives:

I = 32.1210889465256 where sizeof(f) = 1000000

Which is close to what I am getting when using n = 1000000 inclusive

If I use trapz in matlab as an estimate I get (because I was not quite getting above):

h = 1e-4

n = 1e6

x = 0:k:100;

f = exp(sin(x)) .* cos(x/40);

I = trapz(f) * h;

disp( sprintf( 'I = %3.13f where sizeof(f) = %d', I, size( f,2) ))

Gives:

I = 32.1210406651714 where sizeof(f) = 1000001

which is close to the answer given in the hand out, but has 1 more (1000001) integral slice

h = 1e-4

n = 1e6

x = 0:k:100-k;

f = exp(sin(x)) .* cos(x/40);

I = trapz(f) * h;

disp( sprintf( 'I = %3.13f where sizeof(f) = %d', I, size( f,2) ))

Gives:

I = 32.1210889465256 where sizeof(f) = 1000000

Which is close to what I am getting when using n = 1000000 inclusive

Using Mathematica for multiple numerical integration methods, I obtained the following:

With symbolic preprocessing I get for all except Adaptive Quasi Monti Carlo:

32.121040666359182679

- Code:
`In[1]:= methods={"TrapezoidalRule","LobattoKronrodRule","ClenshawCurtisRule","GlobalAdaptive","AdaptiveQuasiMonteCarlo","Trapezoidal"};`

In[2]:= Transpose[{methods,

NIntegrate[Exp[Sin[x]] Cos[x/40],{x,0,100},WorkingPrecision->20,MaxRecursion->10,Method->{#,"SymbolicProcessing"->False}] &/@methods}]//MatrixForm

(* With symbolic processing on all methods except Adaptive Quasi Monti Carlo agree *)

Out[2]//MatrixForm=

TrapezoidalRule 32.121040662893400086

LobattoKronrodRule 32.121040666359180972

ClenshawCurtisRule 32.121040666359182604

GlobalAdaptive 32.121040666359182679

AdaptiveQuasiMonteCarlo 32.121031008894073593

Trapezoidal 32.121022966593591738

With symbolic preprocessing I get for all except Adaptive Quasi Monti Carlo:

32.121040666359182679

Thanks Andrew. I think I found it the bug. Not sure about Mathematica and how it is calculating, but I'll take the output you generated as what it should be. I am now getting similar results.

Thanks

Thanks

10 posts
• Page **1** of **1**

Return to ME964 Spring 2011: High Performance Computing

Users browsing this forum: No registered users and 1 guest