Python Program For Method Of False Position

Introduction

The method of false position, popularly known as the Regula Falsi method, is a numerical approach used in solving nonlinear equations. But this method is especially efficient when the root lies at a particular interval. Here, we will get into the basics of the False Position Method and have a working code in Python.

Understanding the Method of False Position:

The Method of False Position is an iteration method that improves the root estimate from function values at the endpoints of the interval. Unlike the bisection method, which breaks away the segment evenly throughout time, the wrong position has a false function value at both corners of the segment to analyze the root. This enhances efficacy than the bisection method in some cases.

Algorithm Overview:

The algorithm for the Method of False Position involves the following steps:

1. Choose an initial interval [a, b] where the root lies.

2. Find values for function values f(a) and f(b), respectively.

3. Compute the estimate of the root using the formula:

Python Program For Method Of False Position

4. Evaluate the function at the new estimate, i.e., f(c).

5. Update the interval [a, b] depending on the sign of f(c).

  • If f(c) has the same sign as f(a), update a= c.
  • If f(c) has the same sign as f(b), update b= c.
  • If f(c) is close to zero, the solution has been found and the algorithm terminates.

6. Perform steps 3-5 iteratively until the desired level of accuracy is obtained.

In the next section, we will see the code implementation of the method of false position.

Code Implementation:

In Python, the Method of False Position will now be used. We`ll generate a procedure, expecting the function for finding the roots, initial intervals [a, b], as well as the tolerance as input arguments.

Output:

Root found: 2.0 after 0 iterations.

Explanation:

  • The false_position_method function is defined, taking a target function, initial interval endpoints, and optional parameters for tolerance and maximum iterations. The algorithm uses a refinement step wherein the root approximation is iteratively refined within the specified band.
  • The target function values at the endpoint of the interval are determined.
  • The false position formula takes into account the function value at the leftmost end and the value at the rightmost end of the function, and this leads to the determination of the root estimate.
  • A convergence test determines whether the estimated root satisfies the tolerance given.
  • Depending on the sign of the product of function values, a new interval '[a,b]' is selected, and the search space is narrowed.
  • The loop is running up to the point when the root is found within the set tolerance or before the number of iterations is incremented to the maximum one.
  • The ideal code shows one where the application of a cubic function concludes the use of the Method of False Position as a method of finding a root in an interval [0, 2].

Let us see the graphical representation of the method of false position.

Code Implementation:

To integrate data visualization in the form of code that we were given, it is necessary to visualize the convergence of the method of false position for plotting changes in the root estimates over iterations. For this, we can use the 'matplotlib' library. Below is an extended version of the code with data visualization:

Output:

Python Program For Method Of False Position
Root found: 2.0 after 0 iterations.

Explanation:

  • The above code has been extended to visualise the Method of False Position's convergence.
  • A 'roots' list is now used to store the root estimates at all iterations for further visualization.
  • Using the 'matplotlib' library, the convergence is plotted with axes x and y showing iterations and root estimates, respectively.
  • The resulting plot visually demonstrates how the root estimate evolves throughout the iterations of the Method of False Position.
  • This diagram improves understanding and gives information on the convergence tendency of the algorithm.
  • The modified function, ' false_position_method_with_plot ', provides the root estimate, the number of iterations, and a list of estimated roots for further examination.

Conclusion

The Method of False Position is one of the most efficient solutions to approximate the roots of nonlinear equations in an interval of given magnitudes. In this descriptive, we discussed the algorithm implementations of the given method and implemented it in Python. This numerical method is useful for numerous scientific and engineering problems, the subject matters of the numerical analysis doom. By knowing what these approaches are and putting them into use, programmers can better align themselves with the solutions to real-life issues that entail the alley of nonlinear equations' root findings.