Skip to content

maths-polynomial_evalutation #1214

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

Merged
merged 2 commits into from
Oct 1, 2019

Conversation

msk4862
Copy link
Contributor

@msk4862 msk4862 commented Sep 30, 2019

Added code for evaluating a polynomail f(x) for a value of x.

"""
i = 0
res = 0
for c in poly:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for i, c in enumerate(poly): # then delete lines 14 and 10

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the whole function can be a one-liner: return sum(c * x ** i for i, c in enumerate(poly))

poly: tuple of numbers - value of cofficients
x: value for x in f(x)
Return: value of f(x)
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a doctest:

    >>> evaluate_poly((0.0, 0.0, 5.0, 9.3, 7.0), 10)
    79800.0

Then makes sure it passes locally with: python3 -m doctest -v maths/polynomial_evaluation.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cclauss thanks for the suggestion!
will do the changes.

@msk4862
Copy link
Contributor Author

msk4862 commented Oct 1, 2019

@cclauss you can review the changes now.

Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are passing https://travis-ci.org/TheAlgorithms/Python/builds/591848844#L670

Thanks for your contribution. Congratulations!

@cclauss cclauss merged commit b738281 into TheAlgorithms:master Oct 1, 2019
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* maths-polynomial_evalutation

* added doctest and removed redundancy
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

Successfully merging this pull request may close these issues.

2 participants