I need to equalize two coeff matrix

2 ビュー (過去 30 日間)
Burak Bayca
Burak Bayca 2019 年 12 月 2 日
コメント済み: Burak Bayca 2019 年 12 月 2 日
Hi guys, I'm trying to find an answer to this algorithm. That works like the coefficients of s^3+k1*s^2+2*k1*k2*s+6*k1*k3 are equal to the coefficients of s^3+2*s^2+2*s. Then I need to find k1 k2 k3 automatically.
Output like this:
k1 = ...
k2 = ...
k3 = ...
I've tried to make this algorithm bu I could not equalize the coefficient matrices.
Sorry for my English.
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 12 月 2 日
You mean as in k1=2 k2=1 k3=0?. Do you have the symbolic toolbox?
Burak Bayca
Burak Bayca 2019 年 12 月 2 日
Yes I meant this. I have symbolic toolbox. I write syms s k1 k2 k3; to the up of the code. I'm new in MATLAB. Sorry if you do not meant this. I just need a code makes it automatically for this equations.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 12 月 2 日
syms s k1 k2 k3
eqn1 = s^3+k1*s^2+2*k1*k2*s+6*k1*k3;
eqn2 = s^3+2*s^2+2*s;
c1 = coeffs(eqn1, s, 'all');
c2 = coeffs(eqn2, s, 'all');
c1 = [zeros(1, length(c1)-length(c2)), c1];
c2 = [zeros(1, length(c2)-length(c1)), c2];
sol = solve(c1 == c2);
k1 = sol.k1; k2 = sol.k2; k3 = sol.k3;
The step involving zeros() is not needed if you are certain that the two equations have the same maximum degree (they do in the particular example you posted.)
  1 件のコメント
Burak Bayca
Burak Bayca 2019 年 12 月 2 日
Thanks for the answer :) Thats what I want.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by