Giter Site home page Giter Site logo

iamhrithikraj / numerical-algorithm Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 1.0 35 KB

In numerical analysis, a numerical method is a mathematical tool designed to solve numerical problems. The implementation of a numerical method with an appropriate convergence check in a programming language is called a numerical algorithm

License: GNU General Public License v3.0

C++ 100.00%
cpp numerical-methods numerical-analysis numerical-algorithms numerical-approximation adams-bashforth-methods bisection-method gauss-elimination factorization-methods newton-raphson newtons-forward-interpolation gauss-seidel gauss-jordan power-method regula-falsi adams-bashforth trapezoidal-method wave-equation heat-equation laplace-equation

numerical-algorithm's Introduction

Numerical-Algorithm

In numerical analysis, a numerical method is a mathematical tool designed to solve numerical problems. The implementation of a numerical method with an appropriate convergence check in a programming language is called a numerical algorithm

numerical-algorithm's People

Contributors

iamhrithikraj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

kunjshah95

numerical-algorithm's Issues

ANOTHER METHOD TO SOLVE BISECTION METHOD IN C++

#include
#include
#include

// Function definition to calculate the value of the function at a given point
double get_fun(double res) {
return (res * res * res - 4 * res - 9);
}

// Function to perform the bisection method
double bisect(double int_st, double int_end, double err_all, int mx_iter_cnt) {
double mid_pt = (int_st + int_end) / 2;
int iter_cnt = 0;
std::cout << std::fixed << std::setprecision(6);
while (iter_cnt < mx_iter_cnt && fabs(int_st - int_end) > err_all) {
mid_pt = (int_st + int_end) / 2;
std::cout << "Iteration " << iter_cnt + 1 << ": " << mid_pt << std::endl;
if (get_fun(int_st) * get_fun(mid_pt) < 0) {
int_end = mid_pt;
} else {
int_st = mid_pt;
}
++iter_cnt;
}
return mid_pt;
}

int main() {
double int_st, int_end, err_all;
int mx_iter_cnt;
std::cout << "Enter the first starting point: ";
std::cin >> int_st;
std::cout << "Enter the second ending point: ";
std::cin >> int_end;
std::cout << "Enter the maximum iterations to be allowed: ";
std::cin >> mx_iter_cnt;
std::cout << "Input the number of allowed error points: ";
std::cin >> err_all;
double root = bisect(int_st, int_end, err_all, mx_iter_cnt);
std::cout << "The approximate root is: " << root << std::endl;
return 0;
}

ANOTHER METHOD TO SOLVE NEWGTON RHAPSON METHOD IN C++

#include
#include

// Function to compute f(x) = x^2 - 2
double f(double x) {
return x * x * x + x - 1 ;
}

// Function to compute f'(x) = 2x
double f_prime(double x) {
return 3* x + 1 ;
}

int main() {
// Initial values
double x0 = 1.0; // initial guess
double epsilon = 1e-6; // tolerance
int maxIter = 100; // maximum number of iterations

// Initialize variables
double x = x0;
double fx, f_prime_x, x_next;
int iter = 0;

// Newton Raphson method
while (iter < maxIter) {
    // Compute f(x) and f'(x)
    fx = f(x);
    f_prime_x = f_prime(x);

    // Compute x_next
    x_next = x - fx / f_prime_x;

    // Print iteration details
    std::cout << "Iteration " << iter << ": x = " << x << ", f(x) = " << fx << ", f'(x) = " << f_prime_x << ", x_next = " << x_next << std::endl;

    // Check for convergence
    if (std::abs(x_next - x) < epsilon) {
        std::cout << "Converged! The root is approximately " << x_next << std::endl;
        break;
    }

    // Update x
    x = x_next;
    iter++;
}

return 0;

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.