[英]Returning polynomial coefficients from matlabFunction as an array
Using symbolic math I generate a polynomial using poly2sim in the following way : 使用符号数学,我通过以下方式使用poly2sim生成多项式:
nOrderA=input('Power of=')
A = sym('A', [1 nOrderA])
p = poly2sym(A,x)
This returns a polynomial the order of which is dependent on the user input. 这将返回多项式,其阶数取决于用户输入。 In the case of the user input being 3 the output of p is given by 在用户输入为3的情况下,p的输出为
p = (sym)
2
A₁₁⋅x + A₁₂⋅x + A₁₃
I intend to use this output as a function and do this as follows: 我打算将此输出用作函数,并按如下所示进行操作:
F = matlabFunction((p))
This value of F returned is 返回的F的值是
@(A11, A12, A13, x) A11 .* x .^ 2 + A12 .* x + A13
Here instead of the coefficients A11, A12, A13 as separate inputs to the functions, I would like to have them inputted as an array of coefficients ie 在这里,我不想将系数A11,A12,A13作为函数的单独输入,而是希望将它们作为系数数组输入,即
the value of F returned should be 返回的F的值应为
@(A, x) A11 .* x .^ 2 + A12 .* x + A13
where A = [A11,A12,A13]
其中A = [A11,A12,A13]
How should I go about doing this ? 我应该怎么做呢?
Use the coeffs
function: 使用coeffs
函数:
C = coeffs(p)
returns coefficients of the polynomial p
with respect to all variables determined in p
by symvar
. 返回由symvar
在p
确定的所有变量的多项式p
系数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.