Two Quadratics are equal find K1 and K2 cancel out X
1 次查看(过去 30 天)
显示 更早的评论
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
syms K1 K2 l
Atil = A-B*[K1 K2]
lambda = [l 0;0 l] ;
opt1 = det(lambda-Atil) % quadratic with K1 and K2 values
opt2 = l^2+1.5*l+0.5 %set quadratic
solve (opt1==opt2,K1,K2)
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?
0 个评论
采纳的回答
VBBV
2023-3-5
编辑:VBBV
2023-3-5
A =[1 -1; 0 0];
B = [0; 1];
MC = ctrb(A,B); %Gives controllability matrix
det (MC) %Not zero so is controllable
syms K1 K2 l
Atil = A-B*[K1 K2]
lambda = [l 0;0 l] ;
opt1 = det(lambda-Atil) % quadratic with K1 and K2 values
opt1 = collect(opt1) % you can now equate the like terms of opt1 and opt2 and solve for K1 and K2
opt2 = l^2+1.5*l+0.5 %set quadratic
Sol = solve (opt1==opt2,[l,K1,K2])
Sol.l
Sol.K1
Sol.K2
sol = solve(opt1 == opt2,l)
Use collect to rearrange the equation
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Quadratic Programming and Cone Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!