Skip to content
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

Test new approach to second derivative #275

Closed
veillette opened this issue Mar 10, 2023 · 9 comments
Closed

Test new approach to second derivative #275

veillette opened this issue Mar 10, 2023 · 9 comments

Comments

@veillette
Copy link
Contributor

The second derivative is calculated based on the first derivative. Although it is pleasing that we follow mathematical pattern, where the second derivative is merely the derivative of the first derivative, it comes with a set of challenges.

The calculation of the first derivative is only approximate, and therefore introduces errors. As a result, these errors are then baked in our curve. The second derivative accumulates, the error associated with the calculate of a derivative, and then the errors from its basecurve.

We can see the problematic below where I used the flags
numberOfPoints=100&screens=4&allPoints=true

The function is a parabola meeting a line. There is a small error in the function, which affects the derivative, (notice the small kink near the discontinuity). In turns this affects the second derivative. At this point the error has been amplified and it shows a large discrepancy.

image

@veillette
Copy link
Contributor Author

In order to circumvent the artefacts noticed on the second derivative, I suggest trying to calculate the second derivative directly from the original function. I will report my progress in this issue.

@veillette veillette self-assigned this Mar 10, 2023
@veillette
Copy link
Contributor Author

Status: I have made some progress today but I'm not ready to commit it yet. I need to find a clean solution to handle the edges of the curve. Otherwise, it is looking good. I'll come back to it on Monday.

@veillette
Copy link
Contributor Author

I committed my work.

In essence, the second derivative is calculated a double difference, except near discontinuities.
Note that one needs a smooth point to the right and left of a given point to calculate correctly the second derivative. In those
Near discontinuities, there is not enough 'room' to calculate the second derivative, therefore we "borrow" the y-value of the nearby point as a replacement (which is a good approximation, in general, and exact for parabola)

Calculus Grapher screenshot (41).

veillette added a commit that referenced this issue Mar 14, 2023
Signed-off-by: Martin Veillette <[email protected]>
veillette added a commit that referenced this issue Mar 14, 2023
Signed-off-by: Martin Veillette <[email protected]>
@veillette
Copy link
Contributor Author

veillette commented Mar 14, 2023

Assigning to @pixelzoom to review.
The work is all done in SecondDerivativeCurve.ts .
I updated the all the documentation but let me know if I missed anything.
Feel free to close.

@pixelzoom
Copy link
Contributor

This is looking great. One suggestion: rename baseCurve to originalCurve in the subclasses of Curve.

@pixelzoom pixelzoom assigned veillette and unassigned pixelzoom Mar 14, 2023
veillette added a commit that referenced this issue Mar 14, 2023
@veillette
Copy link
Contributor Author

veillette commented Mar 14, 2023

In the commit above, I replaced all references of baseCurve to originalCurve.

This affects three classes: 'DerivativeCurve', 'SecondDerivativeCurve' and 'IntegralCurve'. I also updated local references of basePoints to originalPoints. The documentation has been updated as well.
After the refactoring, I searched for reference to 'base' in the three classes, and I could not find any.

@veillette
Copy link
Contributor Author

Reassigning to @pixelzoom for review.

@veillette veillette assigned pixelzoom and unassigned veillette Mar 14, 2023
@pixelzoom
Copy link
Contributor

I confirmed that there are no remaining occurrences of baseCurve or basePoints. I played around with the sim for awhile, and it's looking good to me. The real test would be to have one of the subject-matter experts take it for a test-drive. I'll assign back to @veillette to decide if he wants to assign to someone else for "behavioral review", or whether to close this issue.

@pixelzoom pixelzoom assigned veillette and unassigned pixelzoom Mar 14, 2023
@veillette
Copy link
Contributor Author

Let close this issue. I created an issue (#292) to let the QA team be on the lookout for this kind of problems.

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

No branches or pull requests

2 participants