MATLAB 中的多项式
多项式是由变量、常数和指数组成的表达式,它们使用数学运算组合,例如加法、减法、乘法和除法(变量不进行除法运算)。 MATLAB 中的多项式表示为包含按降幂排序的系数的向量行。
例如,方程 G(x) = 2x 4 + 3x 3 – 4x + 1 可以表示为 gfg = [2 3 -4 1]。为了评估多项式,我们使用函数polyval(·),它评估 x 中每个点的多项式 gfg。
示例 1:
Matlab
% MATLAB code for example:
% to evaluate our polynomial gfg =
% 2x4 + 3x3 - 4x + 1, at x = 4,
gfg = [2 3 0 -4 1];
GFG= polyval(gfg,4)
Matlab
% MATLAB code for evaluating a polynomial with
% matrices as variables, we use polyvalm( ) function.
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)
Matlab
% MATLAB code for For finding roots
% of polynomial : gfg= 2x4 + 3x3 - 4x + 1,
gfg = [2 3 0 -4 1];
GFG = roots(gfg)
输出:

示例 2:
MATLAB
% MATLAB code for evaluating a polynomial with
% matrices as variables, we use polyvalm( ) function.
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)
输出:

示例 3:
MATLAB
% MATLAB code for For finding roots
% of polynomial : gfg= 2x4 + 3x3 - 4x + 1,
gfg = [2 3 0 -4 1];
GFG = roots(gfg)
输出:
