help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calculation issue with octave (data unexpectedly go to zero at some


From: Ozzy Lash
Subject: Re: Calculation issue with octave (data unexpectedly go to zero at some point)
Date: Thu, 27 Feb 2014 17:41:50 -0600




On Thu, Feb 27, 2014 at 5:16 PM, Ozzy Lash <address@hidden> wrote:

Look, this is hardly a minimalistic code... Indeed, you can isolate
the problem quit eeasily.
If you just print the value of n inside your function
temporalEvolution (I called main(10)), you will see that indeed n
reaches only up to 27 instead of 51.
This says the mod(t, 0.2/Gamma) is zero only 27 times. So the question
to ask is whether the vector "y" in the following code is the same in
matlab and in octave

Gamma = 1.62e7;
duration = 10/Gamma;
dt = 0.0025/Gamma;
t   = 0:dt:duration;
y = mod (t, 0.2/Gamma);
_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave

I think the assumption here is that since 0.2/Gamma is exactly 80 times larger than dt, that every 80th time through n will be incremented.  So since the duration is 4000 time dt (leading to 4001 samples total) it expects the the modulus will be 0 51 times.  It isn't surprising that mod has some issue with this, since comparing to 0 on floating point numbers can be tricky at best.  I tried useing mod(t.0.2/Gamma) < eps, and 2*eps, and they gave more increments, but not the full 51.  I'm surprised that Matlab does as well as it does with this.

Bill


So this comparison works, but probably isn't really the best way to do this:

n=0;
Gamma = 1.62e7;
for t=0:0.0025/Gamma:10/Gamma
        if ((mod (t, 0.2/Gamma) < eps) || mod (t, 0.2/Gamma) > ((0.2/Gamma) -eps))
                n=n+1
        endif
end


The mod function can be either a little greater than 0 or a little less than the base

reply via email to

[Prev in Thread] Current Thread [Next in Thread]