finding variables in polynomial expressions

Hi, have an issue i cant solve with matlab, i wish to get matlab to solve this equation for k1 k2 and ke.
Have tried res = solve((a-b),[k1 k2 ke]) but does not give the results im looking for
clc
clear, close all;
syms s k1 k2 ke
A = [0 -83.33; 500 -10];
B = [166.67; 0];
C= [0 1];
K = [k1 k2];
A2 = [A-B*K B*ke; -C 0];
a = det(s*eye(3)-A2);
b = (s+1600)*(s^2+160*s+30790);
how i do it by hand

 Réponse acceptée

syms s k1 k2 ke
A = [0 -83.33; 500 -10];
B = [166.67; 0];
C= [0 1];
K = [k1 k2];
A2 = [A-B*K B*ke; -C 0];
a = det(s*eye(3)-A2);
b = (s+1600)*(s^2+160*s+30790);
eqn = collect(a-b,s)
eqn = 
sol = solve(coeffs(eqn, s))
sol = struct with fields:
k1: 25000/2381 k2: 45525/16667 ke: 9852800/16667

1 commentaire

fredrik s
fredrik s le 16 Mar 2022
Excellent, just what i was looking for. Thanks alot :D

Connectez-vous pour commenter.

Plus de réponses (1)

Torsten
Torsten le 16 Mar 2022
Modifié(e) : Torsten le 16 Mar 2022
A = [0 -83.33; 500 -10];
B = [166.67; 0];
C = [0 1];
K = @(k1,k2)[k1 k2];
A2 = @(k1,k2,ke) [A-B*K(k1,k2) B*ke; -C 0];
a = @(k1,k2,ke,s) det(s*eye(3)-A2(k1,k2,ke));
b = @(s)(s+1600)*(s^2+160*s+30790);
fun = @(k1,k2,ke)[a(k1,k2,ke,-1)-b(-1);a(k1,k2,ke,0)-b(0);a(k1,k2,ke,1)-b(1)];
sol = fsolve(@(k)fun(k(1),k(2),k(3)),[0;0;0]);
k1 = sol(1)
k2 = sol(2)
ke = sol(3)

1 commentaire

fredrik s
fredrik s le 16 Mar 2022
Thanks, works like a charm. Is it possible to solve with syms s k1 k2 ke, so the decleration @(k1,k2,ke)is avoided in order to easily expand to k1 k2 k3...kn

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by