Skip to content

01-g-h-filter: Exercise: The Effect of Acceleration: Position algorithm appears wrong #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
froohoo opened this issue Jun 21, 2019 · 1 comment

Comments

@froohoo
Copy link
Contributor

froohoo commented Jun 21, 2019

Amazing/Inspiring work here, thank you for sharing the fruits of your research.

It does not impact the message of the section(effect of acceleration) but this code was confusing for me because it appears to be wrong if we are generating position as a function of time with constant acceleration:

    for i in range(count):
        zs.append(x0 + dx*i + randn()*noise_factor)
        dx += accel
    return zs

The calculation of position using x0 + dx*i at step i, implies that velocity was constant (at its current value) for all i up to and including the current step. This overestimates the position. A more accurate representation of the position would be yielded with:

    for i in range(count):
        zs.append(x0 + accel*i**2/2.0 + dx*i + randn()*noise_factor)
    return zs

If there is a desire to stick with a discritized form of the motion equation, something similar to the following might be better, although there is probably a more eloquent way to write it:

    zs = [x0]
    for i in range(1, count):
        dx += accel
        zs.append(zs[-1] + dx + randn()*noise_factor)
    return zs
@rlabbe
Copy link
Owner

rlabbe commented May 4, 2020

Yes, it would be smart to use Newton's equation here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants