FAQ  •  Login

Precision for HW7 & 8

Moderator: Dan Negrut

<<

ME964AbhiramiS

Newbie
Newbie

Posts: 25

Joined: Wed Jan 12, 2011 1:53 pm

Unread post Thu Mar 31, 2011 8:03 pm

Precision for HW7 & 8

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?
<<

Dan Negrut

Global Moderator
Global Moderator

Posts: 833

Joined: Wed Sep 03, 2008 12:24 pm

Unread post Fri Apr 01, 2011 2:05 pm

Re: Precision for HW7 & 8

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
<<

ME964AbhiramiS

Newbie
Newbie

Posts: 25

Joined: Wed Jan 12, 2011 1:53 pm

Unread post Fri Apr 01, 2011 2:15 pm

Re: Precision for HW7 & 8

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

Dan Negrut

Global Moderator
Global Moderator

Posts: 833

Joined: Wed Sep 03, 2008 12:24 pm

Unread post Sun Apr 03, 2011 9:49 am

Re: Precision for HW7 & 8

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

ME964AbhiramiS

Newbie
Newbie

Posts: 25

Joined: Wed Jan 12, 2011 1:53 pm

Unread post Mon Apr 04, 2011 1:40 pm

Re: Precision for HW7 & 8

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?
<<

Andrew Seidl

Administrator
Administrator

Posts: 193

Joined: Thu Oct 28, 2010 11:54 am

Unread post Mon Apr 04, 2011 1:46 pm

Re: Precision for HW7 & 8

<<

ME964AbhiramiS

Newbie
Newbie

Posts: 25

Joined: Wed Jan 12, 2011 1:53 pm

Unread post Mon Apr 04, 2011 4:32 pm

Re: Precision for HW7 & 8

Thanks, Andrew :) Here's my answer: 32.1210406663595
<<

ME964BrianD

Jr. Member
Jr. Member

Posts: 77

Joined: Wed Jan 12, 2011 1:53 pm

Unread post Tue Apr 05, 2011 3:55 pm

Re: Precision for HW7 & 8

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):
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
<<

Andrew Seidl

Administrator
Administrator

Posts: 193

Joined: Thu Oct 28, 2010 11:54 am

Unread post Tue Apr 05, 2011 5:09 pm

Re: Precision for HW7 & 8

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

  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
<<

ME964BrianD

Jr. Member
Jr. Member

Posts: 77

Joined: Wed Jan 12, 2011 1:53 pm

Unread post Tue Apr 05, 2011 6:33 pm

Re: Precision for HW7 & 8

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

Return to ME964 Spring 2011: High Performance Computing

Who is online

Users browsing this forum: No registered users and 1 guest

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software.