Numerical Methods: Applications, Algorithms, and Code

The Importance of Numerical Methods

Numerical methods are crucial for solving complex mathematical problems that lack exact solutions, making them indispensable across various fields:

  • Engineering: Used in simulations like structural analysis, fluid dynamics, and heat transfer.
  • Physics: Models quantum mechanics, astrophysics, and thermodynamics.
  • Finance: Helps with risk analysis, options pricing, and portfolio optimization.
  • Biology/Medicine: Assists in drug modeling, population dynamics, and medical imaging.
  • Computer Graphics: Used for rendering, animations, and physical simulations.
  • Geophysics/Meteorology: Aids in weather forecasting, earthquake simulation, and climate models.
  • Chemistry: Supports molecular simulations and reaction kinetics.
  • Astronomy: Simulates celestial bodies and cosmological phenomena.
  • Mathematics: Solves equations, optimization problems, and performs interpolation.
  • AI/Machine Learning: Optimizes algorithms for model training and simulations.

Regula-Falsi Method Algorithm

  1. Start
  2. Define function as f(x)
  3. Define first derivative of f(x) as g(x)
  4. Input initial guess (x0), tolerable error (e), and maximum iteration (N)
  5. Initialize iteration counter i = 1
  6. If g(x0) = 0 then print “Mathematical Error” and goto (12) otherwise goto (7)
  7. Calculate x1 = x0 – f(x0) / g(x0)
  8. Increment iteration counter i = i + 1
  9. If i >= N then print “Not Convergent” and goto (12) otherwise goto (10)
  10. If |f(x1)| > e then set x0 = x1 and goto (6) otherwise goto (11)
  11. Print root as x1
  12. Stop

Regula Falsi Method

  1. Start
  2. Define function f(x)
  3. Choose initial guesses x0 and x1 such that f(x0)f(x1) < 0
  4. Choose pre-specified tolerable error e.
  5. Calculate new approximated root as: x2 = x0 – ((x0-x1) * f(x0))/(f(x0) – f(x1))
  6. Calculate f(x0)f(x2)
  • if f(x0)f(x2) < 0 then x0 = x0 and x1 = x2
  • if f(x0)f(x2) > 0 then x0 = x2 and x1 = x1
  • if f(x0)f(x2) = 0 then goto (8)
if |f(x2)|>e then goto (5) otherwise goto (8) Display x2 as root. Stop

Bisection Method Algorithm

  1. Start
  2. Define function f(x)
  3. Choose initial guesses x0 and x1 such that f(x0)f(x1) < 0
  4. Choose pre-specified tolerable error e.
  5. Calculate new approximated root as x2 = (x0 + x1)/2
  6. Calculate f(x0)f(x2)
  • if f(x0)f(x2) < 0 then x0 = x0 and x1 = x2
  • if f(x0)f(x2) > 0 then x0 = x2 and x1 = x1
  • if f(x0)f(x2) = 0 then goto (8)
if |f(x2)| > e then goto (5) otherwise goto (8) Display x2 as root. Stop

C Program for Bisection Method

#include <stdio.h>
#include <math.h>

double f(double x) { return x*x*x - x*x + 2; }

void bisection(double a, double b, double tol) {
  double c;
  while ((b - a) >= tol) {
    c = (a + b) / 2;
    if (f(c) == 0.0) break;
    else if (f(c) * f(a) < 0) b = c;
    else a = c;
  }
  printf("Root: %lf\n", c);
}

int main() {
  double a = -200, b = 300, tol = 0.001;
  bisection(a, b, tol);
  return 0;
}

Fixed Point Iteration Method

  1. Start
  2. Define function f(x)
  3. Define function g(x) which is obtained from f(x)=0 such that x = g(x) and |g'(x) < 1|
  4. Choose initial guess x0, Tolerable Error e and Maximum Iteration N
  5. Initialize iteration counter: step = 1
  6. Calculate x1 = g(x0)
  7. Increment iteration counter: step = step + 1
  8. If step > N then print “Not Convergent” and goto (12) otherwise goto (10)
  9. Set x0 = x1 for next iteration
  10. If |f(x1)| > e then goto step (6) otherwise goto step (11)
  11. Display x1 as root.
  12. Stop

Secant Method Algorithm

  1. Start
  2. Define function as f(x)
  3. Input initial guesses (x0 and x1), tolerable error (e) and maximum iteration (N)
  4. Initialize iteration counter i = 1
  5. If f(x0) = f(x1) then print “Mathematical Error” and goto (11) otherwise goto (6)
  6. Calculate x2 = x1 – (x1-x0) * f(x1) / ( f(x1) – f(x0) )
  7. Increment iteration counter i = i + 1
  8. If i >= N then print “Not Convergent” and goto (11) otherwise goto (9)
  9. If |f(x2)| > e then set x0 = x1, x1 = x2 and goto (5) otherwise goto (10)
  10. Print root as x2
  11. Stop.