Two Quadratics are equal find K1 and K2 cancel out X

1 Ansicht (letzte 30 Tage)
Madyson Davis
Madyson Davis am 4 Mär. 2023
Bearbeitet: VBBV am 5 Mär. 2023
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?

Akzeptierte Antwort

VBBV
VBBV am 5 Mär. 2023
Bearbeitet: VBBV am 5 Mär. 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

Weitere Antworten (0)

Kategorien

Mehr zu Quadratic Programming and Cone Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by