-
Notifications
You must be signed in to change notification settings - Fork 33
Neville #88
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
base: master
Are you sure you want to change the base?
Neville #88
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import numpy as np | ||
| import matplotlib.pyplot as plt | ||
| from NevillePoint import nevillepoint | ||
|
|
||
|
|
||
| # [USES] interpolations/NevillePoint | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nu mai e nevoie de asta; delete line |
||
| # Function that calculates the Neville interpolation polynomial for a vector | ||
| # of points (a, b) with a:xs, b:ys in "elements" points between the first of xs | ||
| # and the last of xs; it also plots the interpolation | ||
| def nevilleinterpolation(xs, ys, elements=100): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nevilleinterpolation -> NevilleInterpolation, please |
||
| n = len(xs) | ||
| xss = np.linspace(xs[0], xs[n - 1], elements) | ||
| # create an empty vector to store the values of the interpolation in the | ||
| # xss' points | ||
| yss = [] | ||
|
|
||
| for i in range(0, len(xss)): | ||
| # Calculate the approximation of the function in xss(i) | ||
| yss.append(nevillepoint(0, n - 1, xss[i], xs, ys)) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change to |
||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leave only one blank line |
||
|
|
||
|
|
||
| print(yss) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For Python you can use YAPF[1] for automated code formatting - it is based on building the AST of the program and then printing it out directly in the proper format. Examples of how to configure these tools can also be found in the yapf repo[1], by looking at the proper configuration files (e.g., .style.yapf or pylintrc). [1] https://github.com/google/yapf |
||
| # plot the interpolated function | ||
| plt.plot(xss, yss) | ||
| # plot the initial points as circles | ||
| plt.plot(xs, ys, 'o', "linewidth", 3) | ||
| plt.show() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Function that calculates the value of the Neville interpolation polynomial | ||
| # P_ij(x) for a vector of points (a, b) with a:xs, b:xs in the abscissa x; | ||
| # [NOTE] It doesn't use explicit caching (just the internal Octave caching | ||
| # system) | ||
|
|
||
|
|
||
| def nevillepoint(i, j, x, xs, ys): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nevillepoint -> NevillePoint |
||
| # Base case: P_ii(x) = f(x_i) | ||
| # ys is 1 - indexed, so we have to add one to the index | ||
| if i == j: | ||
| y = ys[i] | ||
| return y | ||
|
|
||
| # x_j - x_i | ||
| delta = xs[j] - xs[i] | ||
| # P(i, j - 1, x) | ||
| pij_ = (xs[j] - x) * nevillepoint(i, j - 1, x, xs, ys) | ||
| # P(i + 1, j, x) | ||
| pi_j = (x - xs[i]) * nevillepoint(i + 1, j, x, xs, ys) | ||
| # P(i, j, x) | ||
| y = (pij_ + pi_j) / delta | ||
| return y | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete blank line