Two Quadratics are equal find K1 and K2 cancel out X

1 view (last 30 days)
So I am coding something that will include two variables that are taking place of constants in a quadratic equation. We have a quadratic that is equal to the first equation so we can solve it by hand but I want to verify my numbers. However the solutions for K1 and K2 keep getting messed up by the x value (which in this code is deemed l) which should cancel out.
A =[1 -1; 0 0];
B = [0; 1];
MC = ctrb(A,B); %Gives controllability matrix
det (MC) %Not zero so is controllable
ans = 1
syms K1 K2 l
Atil = A-B*[K1 K2]
Atil = 
lambda = [l 0;0 l] ;
opt1 = det(lambda-Atil) % quadratic with K1 and K2 values
opt1 = 
opt2 = l^2+1.5*l+0.5 %set quadratic
opt2 = 
solve (opt1==opt2,K1,K2)
ans = struct with fields:
K1: - (5*l)/2 - 1/2 K2: 0
as you can see both can be put into the form of l^2+number*l+number so you should be able to take each section before the l to set it equal but I am not sure how to set that up correclty in matlab without individually manually making each section a variable anyone know an automated way for it?

Accepted Answer

VBBV
VBBV on 5 Mar 2023
Edited: VBBV on 5 Mar 2023
A =[1 -1; 0 0];
B = [0; 1];
MC = ctrb(A,B); %Gives controllability matrix
det (MC) %Not zero so is controllable
ans = 1
syms K1 K2 l
Atil = A-B*[K1 K2]
Atil = 
lambda = [l 0;0 l] ;
opt1 = det(lambda-Atil) % quadratic with K1 and K2 values
opt1 = 
opt1 = collect(opt1) % you can now equate the like terms of opt1 and opt2 and solve for K1 and K2
opt1 = 
opt2 = l^2+1.5*l+0.5 %set quadratic
opt2 = 
Sol = solve (opt1==opt2,[l,K1,K2])
Sol = struct with fields:
l: [2×1 sym] K1: [2×1 sym] K2: [2×1 sym]
Sol.l
ans = 
Sol.K1
ans = 
Sol.K2
ans = 
sol = solve(opt1 == opt2,l)
sol = 
Use collect to rearrange the equation

More Answers (0)

Categories

Find more on Quadratic Programming and Cone Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!