Implementation of Numerical Solutions for Nonlinear Equations using MATLAB

Reader Impact Factor Score
[Total: 7 Average: 5]

Published on International Journal of Biology, Physics & Mathematics
Publication Date: August, 2019

Hnin Hnin Khaing & Yee Yee Htun
Lecturer, Department of Engineering Mathematics, TU (Maubin), Ayarwaddy Division
Lecturer, Department of Engineering Mathematics, TU (Hmawbi), Yangon Division

Journal Full Text PDF: Implementation of Numerical Solutions for Nonlinear Equations using MATLAB.

Problems that most frequently encountered are nonlinear equations in sciences and engineering problems. In this paper, we will focus on MATLAB solutions to nonlinear equations by studying various methods. In this paper, the numerical methods for solving nonlinear equations using MATLAB can be carried out. This present the most widely used iterative methods for nonlinear equations and MATLAB features for finding numerical solutions. The numerical examples are considered and implemented in this paper.

Keywords: nonlinear equations, MATLAB, numerical methods, iteratives methods.

Compare to linear algebraic equations, most frequently encountered are nonlinear equations in sciences and engineering problems. Solving nonlinear equations could be computationally expensive; therefore, the solving of approximate linear equations was indispensable especially in the early times when the computers were not powerful enough. Today, with the rapid development of computing technology, solving directly nonlinear equations is becoming increasingly important. In this paper, various methods of solving nonlinear equations problems are studied and we will focus on MATLAB solutions to nonlinear equations. The three methods of solutions to nonlinear algebraic equations will be presented in this technical approach paper. The graphical method for nonlinear equations with one and two unknown variables can be analysis with polynomial equations. Numerical solutions to nonlinear equations and nonlinear matrix equations can also be implemented in this paper. (Dingyü Xue, 2009).
Graphical and numerical methods will be presented and the simplest solution is implemented using MATLAB. In this paper, the linear programming, quadratic programming and general nonlinear programming will be studied and MATLAB-based solutions will be carried out. As a procedure, the theory background of Bisection Method, Secant Method and Newton Raphson Method of solving nonlinear equations problems are studied and carried out. Then, to be approached to simplest and fast way, MATLAB instructions relative to nonlinear equations solving process are also studied and tested. Actually, various possible problems are applied to three methods and tested. But, only the main points or examples are expressed in this paper as a portion of Mathematical approach to Engineering Problems.

2.1 Bisection method
The idea behind the Intermediate Value Theorem can be stated: when we have two points connected by a continuous curve, as shown in Picture 1:
• one point below the line
• the other point above the line
• then there will be at least one place where the curve crosses the line.

Picture 1(a). Intermediate values Picture 1(b). Bisection Algorithm
(www mathsisfun com) (www codewithc com)

The first step in iteration is to calculate the mid-point of the interval [ a, b ]. If c be the mid-point of the interval, it can be defined as: c = ( a+b)/2. The function is evaluated at ‘c’, which means f(c) is calculated.
• f(c) = 0 : c is the required root of the equation.
• f(b) * f(c) > 0 : if the product of f(b) and f(c) is positive, the root lies in the interval [a, c].
• f(b) * f(c) < 0 : if the product of f(b) and f(c) is negative, the root lies in the interval [ b, c].
In the second iteration, the intermediate value theorem is applied either in [a, c] or [ b, c], depending on the location of roots. And then, the iteration process is repeated by updating new values of a and b. Picture 2 shows how iteration done in bisection method.

Picture 2. Iteration Process in Graph
2.2 Secant Method
This method uses two initial guesses and finds the root of a function through interpolation approach. For each successive iteration, two of the most recent guesses can be used as two most recent fresh values to find out the next approximation. Features of Secant Method can be shortly expressed as:
• No. of initial guesses – 2
• Type – open bracket
• Rate of convergence – faster
• Convergence – super linear
• Accuracy – good
• Approach – interpolation
• Programming effort – tedious
The Procedure of Secant Method can be shown as flowchart as in Picture 3 compare with Newton Raphson Method and this will give the algorithm to implement in MATLAB.

(a) Secant Method Algorithm (b) Newton Raphson Method Algorithm
Picture 3. Comparison of Secant Method and Newton Raphson (www codewithc com)

2.3 Newton Raphson Method
The theoretical and mathematical background behind Newton-Raphson method and its MATLAB program (or program in any programming language) is approximation of the given function by tangent line with the help of derivative, after choosing a guess value of root which is reasonably close to the actual root. The x- intercept of the tangent is calculated by using elementary algebra, and this calculated x-intercept is typically better approximation to the root of the function. This procedure is repeated till the root of desired accuracy is found. Lets now go through a short mathematical background of Newton’s method. For this, consider a real value function f(x) as shown in the Picture 3(c).

Picture 3(c). Newton’s Method (Dingyü Xue, 2009)

Let’s try the example problem using Newton-Raphson method, solving it numerically. The function is to be corrected to 9 decimal places. For a given function: x3−x−1 = 0, which is differentiable,

3.1 Function “roots”
The Syntax : r = roots(p) returns the roots of the polynomial represented by p as a column vector. Input p is a vector containing n+1 polynomial coefficients, starting with the coefficient of xn. A coefficient of 0 indicates an intermediate power that is not present in the equation. This function can study as shown in Picture 4(a). For example: p = [3 2 -2] represents the polyno-mial 3×2+2x−2.The roots function solves polynomial equations of the form p1xn + …+ pnx + pn+1 =0. Polynomial equations contain a single variable with nonnegative exponents.

(a) roots() (b) fzero()
Picture 4. Study on MATLAB Functions

3.2 Function: “fzero”
Root of nonlinear function (fzero) can be write in syntax as:

3.3 Function: “inline”
The constructing of inline object can be scriptable in MATLAB as the fucncitons: inline (expr), inline (expr,arg1,arg2,…) or inline (expr,n). “inline (expr)” constructs an inline function object from the MATLAB expression contained in “expr”. The input argument to the inline function is automatically determined by searching expr for an isolated lower case alphabetic character, other than i or j, that is not part of a word formed from several alphabetic characters. If no such character exists, x is used. If the character is not unique, the one closest to x is used. If two characters are found, the one later in the alphabet is chosen. “inline (expr,arg1,arg2,…)” constructs an inline function whose input arguments are specified by arg1, arg2,…. Multicharacter symbol names may be used. “inline (expr,n)” where n is a scalar, constructs an inline function whose input arguments are x, P1, P2, … .
Three commands related to inline allow you to examine an inline function object and determine how it was created. “char(fun)”converts the inline function into a character array. This is identical to “formula(fun)”. “argnames(fun)” returns the names of the input arguments of the inline object fun as a cell array of character vectors. “formula(fun)” returns the formula for the inline object fun.A fourth command “vectorize(fun)” inserts a . before any ^, * or /’ in the formula for fun. The result is a vectorized version of the “inline” function. (www mathworks com)

3.4 Function “num2str”, “abs”, “plot”
The simple functions of “num2str” which convert number to string, “abs” wich convert the valuse to be absolute or real only and “plot” which make data to graph or curve are also studied and apply in solution of nonlinear equations of MATLAB. Picture 5 shows example expression of these functions which can be studied by help of MATLAB.

(a) num2str() (b)abs()

(c) Plot()
Picture 5. Study on MATLAB Functions

4.1 M-Scripts for Three Methods
Input data are made as variable for any nonlinear equations, not only by getting answer, plotting graph process was followed at the end of program. The m-script for each method was carried out as in the following Table 1:
Table 1. Implemeting Codes of MATLAB

4.2 Simulation Results
The simulation results are shown in Picture 6 to Picture 8. We can study, analyze, compare and solve fastly and simply with our implemented MATLAB program for any nonlinear equations.

(a) m-file Running Results (b) Error Plot
Picture 6. Bisection Method Results

(a) m-file Running Results (b) Error Plot
Picture 7. Secant Method Results

(a) m-file Running Results (b) Error Plot
Picture 8. Newton Raphson Method Results

Picture 9. Results Comparison for ( )

The Implementatin of Numerial Solutions for Non Linear Equations are sucessfully done in this research paper using MATLAB. By this practicle approach, we can easily compare and anlyse any nonlinear equations which are mostly represented in real- world Engineering process. How we can compare and used each method of Bisection, Secant and Newton Raphson’s can be express as shown in Picture 9 for a given same nonlinear equation of . We can proof that Bisection Method was simplest form. For Secant Method, it is faster than other numerical methods, except the Newton Raphson method and there is no need to find the derivative of the function as in Newton-Raphson method. If the function is not differentiable, Newton’s method cannot be applied. By this research paper, we can clearly analyze how nonlinear equations are easily be solved using various method by the help of MATLAB.