Find coefficient in symbolic expression or matrix in matlab

조회 수: 1 (최근 30일)
Amir Ehsani
Amir Ehsani 2012년 10월 27일
댓글: Ozgur 2015년 2월 18일
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. "

채택된 답변

Star Strider
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]
See the coeffs documentation for more information.
  댓글 수: 2
Ozgur
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
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 CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by