收集系数
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
收集系数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 bothx
和y
by 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
i
和PI.
收集系数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)
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]
通过将函数名称指定为第二个参数来收集对特定功能的调用系数。通过将多个函数指定为字符向量的小区阵列来收集多个功能的函数调用的系数。
收集调用的系数sin
功能在F
, whereF
contains 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 thesin
和COS.
functions inF
.
收集(F,{‘因为’‘罪恶’})
答= (c + d)*cos(x) + (a + b)*sin(2*x) + (e + f)*sin(3*x)