主要内容

收藏

收集系数

Description

example

收藏(P)收藏s coefficients inP默认变量的权力P. The default variable is found bysymvar.

example

收藏(P,expr.)收藏s coefficients inP符号表达的权力expr.. IfP是矢量或矩阵,然后收藏acts element-wise onP. Ifexpr.is a vector, then收藏finds coefficients in terms of all expressions inexpr..

Examples

Collect Coefficients of Powers of Default Variable

Collect the coefficients of a symbolic expression.

syms x coeffs = collect((exp(x) + x)*(x + 2))
coeffs = x ^ 2 +(exp(x)+ 2)* x + 2 * exp(x)

因为您没有指定变量,收藏uses the default variable defined bysymvar. For this expression, the default variable isx.

symvar((exp(x) + x)*(x + 2), 1)
答= x

Collect Coefficients of Powers of a Particular Variable

收集系数of a particular variable by specifying the variable as the second argument to收藏.

收集系数of an expression in powers ofx, and then in powers ofy.

syms x y coeffs_x = collect(x ^ 2 * y + y * x  -  x ^ 2  -  2 * x,x)coeffs_y = collect(x ^ 2 * y + y * x  -  x ^ 2  -  2 * x,y)
coeffs_x = (y - 1)*x^2 + (y - 2)*x coeffs_y = (x^2 + x)*y - x^2 - 2*x

收集系数in powers of bothxyby specifying the second argument as a vector of variables.

syms a b coeffs_xy = collect(a^2*x*y + a*b*x^2 + a*x*y + x^2, [x y])
coeffs_xy = (a*b + 1)*x^2 + (a^2 + a)*x*y

Collect Coefficients in Terms ofiPI.

收集系数of an expression in terms ofi, and then in terms ofPI..

syms x y coeffs_i = collect(2*x*i - 3*i*y, i) coeffs_pi = collect(x*pi*(pi - y) + x*(pi + i) + 3*pi*y, pi)
coeffs_i = (2*x - 3*y)*1i coeffs_pi = x*pi^2 + (x + 3*y - x*y)*pi + x*1i

收集符号表达式和函数的系数

收集系数of expressions and functions by specifying the second argument as an expression or function. Collect coefficients of multiple expressions or functions by using vector input.

Expandsin(x + 3*y)和收藏coefficients ofCOS.(y),然后是两者sin(x)sin(y).

syms x y f = expand(sin(x + 3*y)); coeffs_cosy = collect(f, cos(y))
coeffs_cosy = 4*sin(x)*cos(y)^3 + 4*cos(x)*sin(y)*cos(y)^2 + (-3*sin(x))*cos(y) - cos(x)*sin(y)
coeffs_sinxsiny = collect(f, [sin(x) sin(y)])
coeffs_sinxsiny =(4 * cos(y)^ 3  -  3 * cos(y))* sin(x)+(4 * cos(x)* cos(y)^ 2  -  cos(x))* sin(y)

收集系数of the symbolic functionY(x)in a symbolic expression.

syms y(x) f = y^2*x + y*x^2 + y*sin(x) + x*y; coeffs_y = collect(f, y)
coeffs_y(x)= x * y(x)^ 2 +(x + sin(x)+ x ^ 2)* y(x)

Collect Coefficients for Each Element of Matrix

Call收藏在矩阵上。收藏acts element-wise on the matrix.

syms x y collect([(x + 1)*(y + 1), x^2 + x*(x -y); 2*x*y - x, x*y + x/y], x)
答= [ (y + 1)*x + y + 1, 2*x^2 - y*x] [ (2*y - 1)*x, (y + 1/y)*x]

Collect Coefficients of Function Calls

通过将函数名称指定为第二个参数来收集对特定功能的调用系数。通过将多个函数指定为字符向量的小区阵列来收集多个功能的函数调用的系数。

收集调用的系数sin功能在F, whereFcontains multiple calls to different functions.

syms a b c d e f x F = a*sin(2*x) + b*sin(2*x) + c*cos(x) + d*cos(x) + e*sin(3*x) +f*sin(3*x); collect(F, 'sin')
答= (a + b)*sin(2*x) + (e + f)*sin(3*x) + c*cos(x) + d*cos(x)

收集系数of calls to both thesinCOS.functions inF.

收集(F,{‘因为’‘罪恶’})
答= (c + d)*cos(x) + (a + b)*sin(2*x) + (e + f)*sin(3*x)

Input Arguments

collapse all

Input expression, specified as a symbolic expression, function, vector, or matrix.

Expression in terms of which you collect the coefficients, specified as a symbolic number, variable, expression, function, or vector; a character vector; a cell array of character vectors.

Example:i,PI.,x,sin(x),Y(x),[sin(x) cos(y)],{'sin' 'cos'}.

在R2006A之前介绍