Find coefficient in symbolic expression or matrix in matlab
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Star Strider
on 27 Oct 2012
Edited: Star Strider
on 27 Oct 2012
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 Comments
Ozgur
on 18 Feb 2015
I do not know if you noticed, but this code above doesn't result as [2,3,4]. It results equation itself...
More Answers (1)
Azzi Abdelmalek
on 27 Oct 2012
Edited: Azzi Abdelmalek
on 27 Oct 2012
syms x y z
u=2*x+3*y+4*z
[c,t] = coeffs(u, [x y z])
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!