Re: allocate array
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 9 Nov 2006 19:53:18 +0000 (UTC)
Richard E Maine <nospam@xxxxxxxxxxxxx> wrote:
nakisa <nakisa.nooraee@xxxxxxxxx> wrote:(snip)
do x=-2,2,0.01
The above is generally a bad idea. In fact, it is formally obsolescent.
Because of floatting point rounding, you basically can't tell how many
times this loop will go and you can't tell whether the last value will
be close to 2 or closer to 1.99. It may well vary from one compiler to
another.
That is true, but it might not matter for a case like this.
Presuming that the -2 and 2 are sufficiently outside the expected
range of zeros, the goal is a sufficiently fine search through
possible roots.
There are several alternative ways to do this, as discussed in
previous threads here.
if ( abs (function ) .eq. 0 ) then
The above test is an even worse idea. This one probably just won't work
at all unless you are unusually lucky. You can't expect any of your
function results to be exactly zero.
But this, especially with the DO is very unlikely to work.
With something like Newton's method for root finding the solution
will come very close, though often not exactly, to the zero.
Maybe half the time it will be zero.
With steps of 0.01, it is likely that the solution is off by some
multiple of 0.01, and so extremely unlikely to be zero.
Not so bad for zero cross detection, though.
-- glen
.
- Follow-Ups:
- Re: allocate array
- From: nakisa
- Re: allocate array
- References:
- allocate array
- From: nakisa
- Re: allocate array
- From: Richard E Maine
- allocate array
- Prev by Date: Re: array bounds checking -- comparing compilers
- Next by Date: Re: allocate array
- Previous by thread: Re: allocate array
- Next by thread: Re: allocate array
- Index(es):
Relevant Pages
|