Re: allocate array



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
.



Relevant Pages

  • Re: Rounding off double precision
    ... I'd like it to be zero. ... You can't get "output rounded so that errors in calculation are not ... appropriately if you use an F edit descriptor. ... unless the number is indeed exactly zero. ...
    (comp.lang.fortran)
  • Re: Problem with zero result
    ... It seems unlike that you mean when the result of this expression is zero, ... could return anything other than Null if [Lunch Taken]-were ... it only *looks* like it is exactly zero. ... If the fields are not Date/Time fields, ...
    (microsoft.public.access.queries)
  • Re: Recruiters who place people first...
    ... exactly zero. ... submit it in a maths exam, but I can't think of a good reason why it's ... A probability of zero doesn't mean it can't happen. ...
    (alt.sysadmin.recovery)
  • Re: Removing Zeros from a Matrix
    ... If the zeros are EXACTLY zero, ... Thanks for your suggestion. ... data with the non zero elements:- (I do not know how to get the ...
    (comp.soft-sys.matlab)
  • Re: Rounding errors
    ... >fractions with an arbitrary precision then the average will indeed be ... That's because a fraction will not produce zero. ... After rounding was applied, the sum became 500,500. ... On one report you might say you are ...
    (comp.lang.cobol)