Discrepancy between tvec and vector

Anything that doesn't fit elsewhere.
Post Reply
NickHananeia
Posts: 8
Joined: Fri Jun 14, 2019 1:09 pm

Discrepancy between tvec and vector

Post by NickHananeia »

I hope this is something minor that I'm missing, but I've noticed a weird discrepancy between my tvec and a voltage vector when I need 1:1 correspondence, but only depending on the time step.

The program that I've written has a selectable time step as a parameter: 5us or 25us, and this is set pretty early in the program.

I declare my tvec like this:

tvec = new Vector()
tvec.indgen(0.000000, tstop, dt)

and I've verified after it's saved externally that it's correct for both the 5us and 25us case.

Then, I declare a list of voltage vectors...

obfunc recallv() { localobj tmplist, tmpvec
tmplist = new List()
forall for (x,0) {
tmpvec = new Vector()
tmpvec.record(&v(x), tvec)
tmplist.append(tmpvec)
}
return tmplist
}

For the 5us case, it works - my test case for a 10ms run has 2001 lines in the tvec and 2001 lines in the voltage trace.

For the 25us case, however, I have 401 lines in the tvec output and only 400 in the voltage trace. As minor as it is, I don't want to publish code with an off-by-one error.

Any thoughts on what could be happening here?
ted
Site Admin
Posts: 5935
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Discrepancy between tvec and vector

Post by ted »

Roundoff error is your enemy. You have to rely on the standard run system to decide when the simulation ends, but you're using the Vector class's indgen method to fill the t vector. Instead, use Vector.record to capture t, and the resulting recorded t vector will be the same length as the v vectors.
NickHananeia
Posts: 8
Joined: Fri Jun 14, 2019 1:09 pm

Re: Discrepancy between tvec and vector

Post by NickHananeia »

That makes sense. I'd shifted to using the indgen method because of another issue, but I found a workaround for that.

Thanks for the quick solution!
Post Reply