C-Plus-Plus icon indicating copy to clipboard operation
C-Plus-Plus copied to clipboard

Added Jacobi Method for solving System of Linear Equations

Open NitishPal2013 opened this issue 3 years ago • 1 comments

Description of Change

Checklist

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

Notes: The very first Iterative approach for approximating the solution of system of linear equations.

NitishPal2013 avatar Oct 18 '22 21:10 NitishPal2013

Sir, I have made the changes that you have suggested locally but I am stuck with an error. I cannot push from my local environment to github. When I am giving this command

git push origin C++_NumericalMethods",

it gives me the following error :

To https://github.com/NitishPal2013/C-Plus-Plus.git ! [rejected] C++_NumericalMethods -> C++_NumericalMethods (non-fast-forward) error: failed to push some refs to ' https://github.com/NitishPal2013/C-Plus-Plus.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

And i have enabled the actions workflow but it is showing the code formatter error . Can you explain this to me ?

What should I do Now?

On Wed, Oct 19, 2022 at 6:07 AM David Leal @.***> wrote:

@.**** requested changes on this pull request.

In numerical_methods/jacobi_method.cpp https://github.com/TheAlgorithms/C-Plus-Plus/pull/2297#discussion_r998828435 :

  • private:
  • int n; ///< n for order of matrix

  • int ite; ///< ite for no. of iterations

  • vector<vector> coeff_matrix; ///< for Coefficient Matrix

  • vector col_vector; ///< for Column vector

  • vector prev; ///< for storing previous values

  • vector succ; ///< for storind updated values

  • float calc(vector x, int k); ///< short calculation part of formula

  • public:

  • jacobi_method(vector<vector> c_m, vector c_v, int iterations);

  • vector jacobi(); /// Algorithm Implementation

+};

+/**

    • @brief jacobi_method()

Please explain what the function does.

In numerical_methods/jacobi_method.cpp https://github.com/TheAlgorithms/C-Plus-Plus/pull/2297#discussion_r998828490 :

    • @param c_v column vector
    • @param iterations number of iterations
  • */

+jacobi_method::jacobi_method(vector<vector> c_m, vector c_v,

  •                         int iterations) {
    
  • n = c_m.size();

  • coeff_matrix = c_m;

  • col_vector = c_v;

  • prev.assign(n, 0);

  • succ.assign(n, 0);

  • ite = iterations;

+}

+/**

    • @brief calc()

Please explain what the function does.

In numerical_methods/jacobi_method.cpp https://github.com/TheAlgorithms/C-Plus-Plus/pull/2297#discussion_r998828558 :

+float jacobi_method::calc(vector x, int k) {

  • float sum = 0; // for consecutive summation

  • for (int i = 0; i < n; i++) {

  •    if (i == k) {
    
  •        continue;
    
  •    }
    
  •    sum += coeff_matrix[k][i] * x[i];
    
  • }

  • return sum;

+}

+/**

    • @brief jacobi()

Please explain what the function does.

In numerical_methods/jacobi_method.cpp https://github.com/TheAlgorithms/C-Plus-Plus/pull/2297#discussion_r998829535 :

    • @return 0 on exit

⬇️ Suggested change

    • @return 0 on exit
    • @returns 0 on exit

In numerical_methods/jacobi_method.cpp https://github.com/TheAlgorithms/C-Plus-Plus/pull/2297#discussion_r998829793 :

    • https://mathworld.wolfram.com/JacobiMethod.html

+#include /// for assert

+#include /// for pow() and round()

+#include /// for IO operations

+#include /// for vector class to storing values

+using std::cout;

+using std::vector;

+/**

    • @namespace jacobi
    • @brief

⬇️ Suggested change

    • @brief
    • @brief Functions for the [Jacobi Method]
  • (https://en.wikipedia.org/wiki/Jacobi_method) implementation


In numerical_methods/jacobi_method.cpp https://github.com/TheAlgorithms/C-Plus-Plus/pull/2297#discussion_r998829874 :

  • (https://en.wikipedia.org/wiki/Jacobi_method#Algorithm)
  • (https://college.cengage.com/mathematics/larson/elementary_linear/5e/students/ch08-10/chap_10_2.pdf)

⬇️ Suggested change

  • (https://en.wikipedia.org/wiki/Jacobi_method#Algorithm)

  • (https://college.cengage.com/mathematics/larson/elementary_linear/5e/students/ch08-10/chap_10_2.pdf)

  • (https://en.wikipedia.org/wiki/Jacobi_method)

In numerical_methods/jacobi_method.cpp https://github.com/TheAlgorithms/C-Plus-Plus/pull/2297#discussion_r998830678 :

+#include /// for IO operations

+#include /// for vector class to storing values

+using std::cout;

+using std::vector;

+/**

    • @namespace jacobi
    • @brief
  • */

+namespace jacobi {

+/**

  • @.*** jacobi_method documentation

    • jacobi_method class is to implement [The Jacobi Method].

Yes, we know it's used to implement the Jacobi Method, but what is the use of its functions/variables (should be a summary)? Why are those created and used?

In numerical_methods/jacobi_method.cpp https://github.com/TheAlgorithms/C-Plus-Plus/pull/2297#discussion_r998829462 :

  • return succ;

+}

+} // namespace jacobi

+/**

    • @brief roundoff()
    • @param value value to be roundoff
    • @param prec number of decimals places
    • @return float
  • */

+float roundoff(float value, unsigned char prec) {

  • float pow_10 = pow(10.0f, (float)prec);

  • return round(value * pow_10) / pow_10;

Seems it's still float type.

— Reply to this email directly, view it on GitHub https://github.com/TheAlgorithms/C-Plus-Plus/pull/2297#pullrequestreview-1146680704, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASFWZS2HRYBORNSVE4IIULTWD47D5ANCNFSM6AAAAAARIPH5BI . You are receiving this because you authored the thread.Message ID: @.***>

NitishPal2013 avatar Oct 19 '22 16:10 NitishPal2013

This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Dec 30 '22 00:12 github-actions[bot]

Please ping one of the maintainers once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to ask for help in our Gitter channel or our Discord server. Thank you for your contributions!

github-actions[bot] avatar Jan 06 '23 00:01 github-actions[bot]