## Introduction to 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

**Syntax**

**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.

**Code:**

`clc ;`

clear all;

eq1 = [ 4, 6, 3 ]
eq2 = [ 5, 3, 2 ]
op = polyval(eq1, eq2)

**Output:**

#### 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.

**Code:**

`clc ;`

clear all ;

eq1 = [ 6, 3, 0, 2 ]
op1 = polyint(eq1)

r1 = 3

r2 = 1

op2 = diff(polyval( op1, [ r1 , r2 ] ))

4.5 (6,935 ratings)

View Course

** Output: **

#### 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

**Code:**

`clc ;`

clear all ;

range = 1 : 50 ;

eq1 = 0.5 * range + 3 * randn(1, 50 ) ;

[ op ,op1] = polyfit(range, eq1, 1)

** Output: **

### Conclusion

In the above modules, we have seen polynomial evolution by using Mat lab. There are various commands we can use to find the exact solution. Such as polyval, polyint, polyder, poly, and polyfit. We can also evaluate arbitrary polynomial by using these commands. Along with these applications, we can also find higher degree polynomial solutions by using polynomial matrix and polynomial regression .polynomial regression is one of the important applications of polyval implementation.

### Recommended Articles

This is a guide to Polyval MATLAB. Here we discuss how does polyval works with appropriate syntax and respective examples to implement. You can also go through our other related articles to learn more –