Welcome to the World of Modelling and Simulation

What is Modelling?

This blog is all about system dynamics modelling and simulation applied in the engineering field, especially mechanical, electrical, and ...

Application of the Taylor Series to Determine the Unknown Coefficients of a Polynomial

Let's say, we have a polynomial equation of the following form. 

y = ax^b + 5

Where, a, and b are the unknown coefficients of the polynomials. In this tutorial, we will discuss a method to determine the unknown coefficients using the Taylor series expansion assuming the data points are provided.

From the above polynomial equation, y is the dependent variable, and x is the independent variable. Let's assume that we know ten data points for the polynomial so that the following equations may be written based on the data points: 

y₁ = ax₁^b + 5

y2 = ax2^b + 5

y3 = ax3^b + 5


y10 = ax10^b + 5

This model seems to have a nonlinear dependence on the parameters a and b. Nonlinear regression can be used here to estimate these parameters. Nonlinear regression is based on determining the values of the parameters that minimize the sum of the squares of the residuals and the solution is preceded in an iterative manner. The Gauss-Newton method is one of the algorithms which minimize the sum of the squares of the residuals between nonlinear equation and data. A Taylor series expansion is used to express the nonlinear equation is an approximate linear form. After that, least square method is applied to estimate the parameters, which move towards the minimization of the residuals.

yi = f(xi; a,b,c) + ei;          i = 1, 2, 3, ... ... ... 10

Where, yi is a measured value of the dependent variable,  f(xi; a,b,c) is the nonlinear function of the independent variable, xi, with two unknown parameters a, b, and one given parameter c, which is 5 according to the given correlation. The last term ei is the random error. The model may be represented in a short form without the parameters for convenience as,

yi = f(xi) + ei                               (1)

For the two parameters case, a Taylor series expansion is written for the first two terms as,

Taylor series expansion for first two terms

Here, j is the initial guess, j+1 is the prediction, ∆a = aj+1 - aj and ∆b = bj+1 - bjEquation (2) is substituted to equation (1) which yields,

Taylor series expansion for first two terms

In matrix form, equation (3) may be written as,

Taylor series in matrix form

Where, Zj is the matrix of the partial derivatives of the function at the initial guess j.

Matrix of the partial derivatives

The vector {D} contains the difference between the measurements and function values at 10 points.

Contains the difference between the measurements and function values

And, the vector {A} contains the changes in the parameters’ values as,

Contains the changes in the parameters

Applying least square method to equation (4) results the following normal equation,

Applying the least square method

Equation (5) is implemented to solve for {∆A} to estimate the improved values of the parameters a and b,

aj+1 = aj + ∆a

bj+1 = bj + ∆b

Thus, this procedure is continued until the solution converges.

#TaylorSeries #Polynomial #NonlinearRegression #LeastSquare #Matlab #Blog #Blogger

Discussion of the Secant Method to Solve an Equation

Let's consider the following equation:

eˣ = 2x² + 1

We may write the above expression as,

f(x) = eˣ - 2x² - 1

To find the value of x or roots of the equation, we may apply the Secant method. In this method, the derivative may be approximated by a backward finite divided difference approach. So, the function may be expressed as,
Secant method expression
This method is convenient when evaluating derivative for some function is difficult in Newton-Raphson method. Now, the above equation may be substituted in Newton-Raphson’s formula to get the following algorithm.
Secant formula
In contrast to Newton-Raphson method, two initial assumptions are made for the two unknowns’ xi-1 and xi.
For the proper initial guess for x, graphical method is applied to visualize the characteristics of the function. The MATLAB commands generate the plot of the function f(x). This function is plotted with respect to the values of x from -10 to +10. The following figure shows the function plot. From the plot, the function changes sign when x is between 2 to 3. So, the root lies in this interval. And, in the program developed for Secant method, two initial guesses for xi-1 and xi are 2 and 3 respectively.

Plot of the function f(x) to identify the interval where root of the function lies

However, more close observation reveals two roots, which are shown in the following figure. In this time, the range of x is decreased significantly for precise investigation between -2 to +2 as this interval seems unclear in the previous figure for the presence of any roots. 

Shows two more roots which lie in between 0.1 to 1, and at origin

So, the above figure shows the existence of other two roots, which lie in between 0.1 to 1 and at the origin. The origin is obvious for this case, and there is no need for any further estimation by numerical methods. But, for the interval 0.1 to 1, the accurate and precise approximation is necessary. For this, the two initial guesses are set to 0.1 and 1 for xi-1 and xi accordingly.
The following Secant formula is implemented to approximate the two roots lie in the intervals 2 to 3 and 0.1 to 1. The results are shown after the program.

Secant Formula Implementation by a MATLAB Program

% Definition of a function "secant" to solve equation by Secant Method
function [x,ea] = secant(X,X0,etol)
format long;
% Input: X,X0, etol=Tolerance definition for error
% Output: x, ea=Calculated error in loop
% Iterative Calculations
while (1)
    % Implementation of Secant Algorithm 
solution = X-((exp(X)-(2*X^2)-1)*(X0-X))/((exp(X0)-(2*X0^2)-1)-(exp(X)-(2*X^2)-1));     
if (solution-solutionprevious)~=0        % Approximate percent relative error
   ea=abs((solution - solutionprevious)/solution)*100;
if ea<=etol,                  
x = solution;
% Display of output parameters


>> secant (3, 2, 1e-5)
% Iterations


>> secant(1, 0.1, 1e-5)
% Iterations


So, the solutions for the equation are 2.842673428005184, 0.740850398734311 and 0.

#SecantMethod #RootsofEquations #Matlab #NumericalMethod #Blog #Blogger