The Wayback Machine - https://web.archive.org/web/20230125141512/https://github.com/TheAlgorithms/C-Plus-Plus/pull/1773
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

feat: Created composite Simpson's numerical integration method #1773

Merged
merged 35 commits into from Nov 3, 2021

Conversation

ggkogkou
Copy link
Contributor

@ggkogkou ggkogkou commented Oct 20, 2021

Description of Change

Created the composite Simpson's numerical method for integrals approximation (wiki: https://en.wikipedia.org/wiki/Simpson%27s_rule#Composite_Simpson's_rule).

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes:
Numerical method for integral evaluation implementation

@ggkogkou
Copy link
Contributor Author

Also created midpoint numerical method for integral approximation

Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

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

Please see the comments by @ayaankhan98.

@Panquesito7 Panquesito7 added enhancement New feature or request requested changes changes required labels Oct 20, 2021
@Panquesito7 Panquesito7 changed the title Created composite Simpson's numerical integration method feat: Created composite Simpson's numerical integration method Oct 22, 2021
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <functional>
#include <map>
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 one-line description of what the library/header is for (see the example below).

#include <iostream>    /// for IO operations
#include <cassert>    /// for assert

*
* Add sample function by replacing one of the f, g, k, l and the assert
*
* @author ggkogkou
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @author ggkogkou
* @author [ggkogkou](https://github.com/ggkogkou)

/**
* @namespace simpson_method
* @brief Contains the Simpson's method implementation
*/
namespace simpson_method{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/**
* @namespace simpson_method
* @brief Contains the Simpson's method implementation
*/
namespace simpson_method{
/**
* @namespace numerical_methods
* @brief Numerical algorithms/methods
*/
namespace numerical_methods {
/**
* @namespace simpson_method
* @brief Contains Simpson's method implementation
*/
namespace simpson_method {

* @returns the result of the integration
*/
double evaluate_by_simpson(int N, double h, double a, std::function<double (double)> func);
} // simspon_method end
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} // simspon_method end
} // namespace simpson_method
} // namespace numerical_methods

@ggkogkou
Copy link
Contributor Author

I updated documentation and namespace as asked to

numerical_methods/composite_simpson_rule.cpp Outdated Show resolved Hide resolved
numerical_methods/composite_simpson_rule.cpp Outdated Show resolved Hide resolved
numerical_methods/composite_simpson_rule.cpp Outdated Show resolved Hide resolved
numerical_methods/composite_simpson_rule.cpp Outdated Show resolved Hide resolved
numerical_methods/composite_simpson_rule.cpp Outdated Show resolved Hide resolved
numerical_methods/composite_simpson_rule.cpp Outdated Show resolved Hide resolved
numerical_methods/composite_simpson_rule.cpp Outdated Show resolved Hide resolved
@ggkogkou
Copy link
Contributor Author

Changes done

@ggkogkou ggkogkou requested a review from Panquesito7 Oct 27, 2021
numerical_methods/composite_simpson_rule.cpp Outdated Show resolved Hide resolved
numerical_methods/composite_simpson_rule.cpp Show resolved Hide resolved
numerical_methods/composite_simpson_rule.cpp Outdated Show resolved Hide resolved
@ggkogkou
Copy link
Contributor Author

Done.

@ggkogkou ggkogkou requested a review from Panquesito7 Oct 28, 2021
Copy link
Member

@ayaankhan98 ayaankhan98 left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. Please fix the issue below.

test.cpp: In function ‘void test(int, double, double, double, bool)’:
test.cpp:96:87: error: ‘f’ was not declared in this scope; did you mean ‘numerical_methods::simpson_method::f’?
   96 |     double result_f = numerical_methods::simpson_method::evaluate_by_simpson(N, h, a, f);
      |                                                                                       ^
      |                                                                                       numerical_methods::simpson_method::f
test.cpp:68:8: note: ‘numerical_methods::simpson_method::f’ declared here
   68 | double f(double x){
      |        ^
test.cpp:100:87: error: ‘g’ was not declared in this scope; did you mean ‘numerical_methods::simpson_method::g’?
  100 |     double result_g = numerical_methods::simpson_method::evaluate_by_simpson(N, h, a, g);
      |                                                                                       ^
      |                                                                                       numerical_methods::simpson_method::g
test.cpp:72:8: note: ‘numerical_methods::simpson_method::g’ declared here
   72 | double g(double x){
      |        ^
test.cpp:104:87: error: ‘k’ was not declared in this scope; did you mean ‘numerical_methods::simpson_method::k’?
  104 |     double result_k = numerical_methods::simpson_method::evaluate_by_simpson(N, h, a, k);
      |                                                                                       ^
      |                                                                                       numerical_methods::simpson_method::k
test.cpp:76:8: note: ‘numerical_methods::simpson_method::k’ declared here
   76 | double k(double x){
      |        ^
test.cpp:108:87: error: ‘l’ was not declared in this scope; did you mean ‘numerical_methods::simpson_method::l’?
  108 |     double result_l = numerical_methods::simpson_method::evaluate_by_simpson(N, h, a, l);
      |                                                                                       ^
      |                                                                                       numerical_methods::simpson_method::l
test.cpp:80:8: note: ‘numerical_methods::simpson_method::l’ declared here
   80 | double l(double x){
      |        ^

shell returned 1

Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

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

Everything else is looking great! 🚀 Just fix the errors mentioned by @ayaankhan98 above, please. Let us know if you need any help! 🙂

numerical_methods/composite_simpson_rule.cpp Outdated Show resolved Hide resolved
numerical_methods/composite_simpson_rule.cpp Outdated Show resolved Hide resolved
@ggkogkou
Copy link
Contributor Author

Done

Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀 Please review, @ayaankhan98. Thanks. 🙂

Copy link
Member

@ayaankhan98 ayaankhan98 left a comment

Choose a reason for hiding this comment

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

👍

@Panquesito7 Panquesito7 merged commit 0c08cd7 into TheAlgorithms:master Nov 3, 2021
7 checks passed
@Panquesito7 Panquesito7 added approved Approved; waiting for merge and removed requested changes changes required labels Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved; waiting for merge enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants