error with trapzd(numerical recipe)
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
error with trapzd(numerical recipe)         


Author: nakisa
Date: Sep 6, 2007 23:56

hi everybody
i use trapzd subroutine from numerical recipe for computing
integral, but it doesn't give correct answer even for simple functions
such as f(x)=x

i can't understand where the error is !!!program is below :

program test
implicit none
real kappa
call trapzd(f,0.,1.,kappa,20)
print *,kappa
Show full article (0.94Kb)
6 Comments
Re: error with trapzd(numerical recipe)         


Author: Arjen Markus
Date: Sep 7, 2007 00:35

On 7 sep, 08:56, nakisa gmail.com> wrote:
> hi everybody
> i use trapzd subroutine from numerical recipe for computing
> integral, but it doesn't give correct answer even for simple functions
> such as f(x)=x
>
> i can't understand where the error is !!!program is below :
>
> program test
> implicit none
> real kappa
> call trapzd(f,0.,1.,kappa,20)
> print *,kappa
>
> contains
> !333333333333333333333333333333
> real function f(x)
> implicit none
> real x
> f=x ...
Show full article (1.64Kb)
no comments
Re: error with trapzd(numerical recipe)         


Author: nospam
Date: Sep 7, 2007 09:16

Arjen Markus wrote:
> 1. You can not pass an internal routine as an actual argument,
> though I am not sure if this also holds if the routine is
> passed to another internal routine (the compiler - g95 - I used
> complained about it)

Yes, the restriction does still hold in that case.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
no comments
Re: error with trapzd(numerical recipe)         


Author: nakisa
Date: Sep 7, 2007 12:29

hi
i had heard that subroutines of numerical recipe are correct, so
didn't check trapezoid subroutine . as you said 0.5 is wrong .
i use the same subroutine to find the answer of double integral .
but when 0.5 is omitted ,the answer is completely out of range.
i guess there is some error in my code which i write it below .
may i ask you to take a look on it ?

behind, i can't understand meaning of the first note , can you say
more please ?
thanks ,nakisa

program test
implicit none
real,parameter::x1=0.
real,parameter::x2=1.
real ss

call trapzd(h,x1,x2,ss,10)
print *,ss
Show full article (1.92Kb)
no comments
Re: error with trapzd(numerical recipe)         


Author: Charles Russell
Date: Sep 7, 2007 20:10

Arjen Markus wrote:
> On 7 sep, 08:56, nakisa gmail.com> wrote:
>> hi everybody
>> i use trapzd subroutine from numerical recipe for computing
>> integral, but it doesn't give correct answer even for simple functions
>> such as f(x)=x
>>
>> i can't understand where the error is !!!program is below :
>>
>> program test
>> implicit none
>> real kappa
>> call trapzd(f,0.,1.,kappa,20)
>> print *,kappa
>>
>> contains
>> !333333333333333333333333333333
>> real function f(x)
>> implicit none
>> real x ...
Show full article (2.69Kb)
no comments
Re: error with trapzd(numerical recipe)         


Author: Charles Russell
Date: Sep 8, 2007 07:36

nakisa wrote:
> hi
> i had heard that subroutines of numerical recipe are correct, so
> didn't check trapezoid subroutine . as you said 0.5 is wrong .
> i use the same subroutine to find the answer of double integral .
> but when 0.5 is omitted ,the answer is completely out of range.
> i guess there is some error in my code which i write it below .
> may i ask you to take a look on it ?

Your code is in f90, so I'll leave comments on the code itself to
others. However, the subroutine trapzd in your posted code is the same
as in the fortran 77 edition of the NR book. There is also a fortran 90
edition, with its own (different) code package. Which book are you
using? Which book do you have the code for? They should match. There
were two editions of the fortran 77 book, again with differences. The
books are available online so you can easily check.
Show full article (1.29Kb)
no comments
Re: error with trapzd(numerical recipe)         


Author: John Harper
Date: Sep 9, 2007 16:15

In article ,
Charles Russell bellsouth.net> wrote:
>
>I think NR is fine for learning numerical methods and for learning how
>a scientist can write quick-and-dirty code for his own use

True, but it might be worth passing on a good reason why I agree.
Some NR routines do not check for inappropriate input, but just give
wrong output.

-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@vuw.ac.nz phone (+64)(4)463 5341 fax (+64)(4)463 5045
no comments