Find coefficient in symbolic expression or matrix in matlab
1 次查看(过去 30 天)
显示 更早的评论
I have the equation below: 2*x+3*y+4*z I want to separate the coefficients from syms. I want a function that its result from my equation be [2 3 4] "some times maybe my coefficients be a symbol too. "
0 个评论
采纳的回答
Star Strider
2012-10-27
编辑:Star Strider
2012-10-27
This should do what you want:
syms x y z
f = 2*x+3*y+4*z
cf = coeffs(f, [z y x])
It results in:
cf =
[ 2, 3, 4]
2 个评论
Ozgur
2015-2-18
I do not know if you noticed, but this code above doesn't result as [2,3,4]. It results equation itself...
更多回答(1 个)
Azzi Abdelmalek
2012-10-27
编辑:Azzi Abdelmalek
2012-10-27
syms x y z
u=2*x+3*y+4*z
[c,t] = coeffs(u, [x y z])
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!