3. Matlab Functions

Polyval MATLAB

‘ Polyval ’ is one of the important syntaxes in Matlab because it is very complex to solve mathematical quadratic or linear equations in computer systems. ‘ polyval ’ supports to resolve these problems. by using polyval command we can solve complex polynomials in Matlab. This command is not limited to one or two degrees but it evaluates roots of “n” number of degrees and roots. It includes other functions also such as poly, polyder, poly int, polyvalm,polyeig, residue, roots, conv, second, and polyfit,. Poly int is used to find definite integration of polynomial. Polyfit is used to fit the first-degree polynomial to the solution. Polyvalm is used to evaluate matrix-vector polynomials. polyeig used to find solution of eigenproblems. To find roots of partial fraction residue command is used. conv is used to do multiplication of convolution and polynomial and deconv s used to do the division of deconvolution and polynomial


  • Op = polyval(eq1 ,eq2): output variable name = polyval (coefficient of polynomial, points location)
  • Op = polyint(eq1): output variable name = polyint(coefficients of polynomial)
  • [op,op1] = polyfit(range ,eq1, 1): Output variable names = polyfit (range, polynomial coefficients, 1)

Why we Use Polyval Matlab?

There are various functions and commands which are used to find out the roots of polynomials but other methods fail to evaluate roots or solutions of higher degree polynomials .in such cases polyval plays a vital role. If we want to find out the roots of polynomials at different locations then we use polyval. Let us assume one equation x 1 = 9 x^3 + 5 x^2 + 4 x + 9 at points 4, 5 , 3, 2 then it will create one vector [ 9, 5, 4, 9 ] . This vector represents coefficients of the polynomial. It also helps to evaluate the definite integral of polynomials. And if we want to fit or use multiple values or ranges then we can use polyfit command.

Examples to Implement Polyval MATLAB

Below are the examples mentioned:

Example 1:

let us consider two equations eq1 = 4 x^2 + 6 x + 3 and eq2 = [ 5, 3, 2 ] , eq2 is location of points . Example 1 shows the Mat lab program to solve this problem. The output of this example will show roots of above eq1 at location 5, 3, and 2.


clc ;
clear all;
eq1 = [ 4, 6, 3 ] eq2 = [ 5, 3, 2 ] op = polyval(eq1, eq2)


Polyval MATLAB - 1

Example 2:

let us consider integration example with limits r1 and r2. Eq1 =6 x^3 + 3 x^2 + 2. In eq1, one degree is missing therefore we will consider coefficient as 0. And values of r 1 and r 2 are 3 and 1. To evaluate this problem first we will calculate the integration of eq1 by using polyint command and after integration, we can find define values by putting output and values of r1 and r2 in polyval command.


clc ;
clear all ;
eq1 = [ 6, 3, 0, 2 ] op1 = polyint(eq1)
r1 = 3
r2 = 1
op2 = diff(polyval( op1, [ r1 , r2 ] ))


Polyval MATLAB - 2

Example 3:

In example3 we have used polyfit function which is used to fit ranges of values of first degree into the polynomial. in this example, the range is considered as 1 to till 50 and it is defined in variable range and polynomial is stored in equation 1 .after assigning the values we fit the polynomial and range in function by using polyfit command. Matlab code shows an implementation of example 3


clc ;
clear all ;
range = 1 : 50 ;
eq1 = 0.5 * range + 3 * randn(1, 50 ) ;
[ op ,op1] = polyfit(range, eq1, 1)


Polyval MATLAB - 3

Leave a Reply

Your email address will not be published. Required fields are marked *