Polynomials in MATLAB
Last Updated :
09 May, 2022
A polynomial is an expression that is made up of variables, constants, and exponents, that are combined using mathematical operations such as addition, subtraction, multiplication, and division (No division operation by a variable). Polynomials in MATLAB are represented as row of a vector containing coefficients ordered by descending powers.
For example, the equation G(x) = 2x4 + 3x3 – 4x + 1 could be represented as gfg = [2 3 -4 1]. For evaluating Polynomials we use function polyval( ), It evaluates the polynomial gfg at each point in x.
Example 1:
Matlab
gfg = [2 3 0 -4 1];
GFG= polyval(gfg,4)
|
Output:
Example 2:
Matlab
gfg = [2 3 0 -4 1];
X = [1 2 -3 4; 2 -5 6 3; 3 1 0 2; 5 -7 3 8];
GFG= polyvalm(gfg, X)
|
Output:
Example 3:
Matlab
gfg = [2 3 0 -4 1];
GFG = roots(gfg)
|
Output:
Share your thoughts in the comments
Please Login to comment...