We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
车参数:
cf=-110000; cr=cf; m=2108; Iz=1585.3; a=1.47; b=2.97-a; k=zeros(1,4); i=1; vx=0.01*i; A=[1,1,0,0; 1,(cf+cr)/(m*vx),-(cf+cr)/m,(a*cf-b*cr)/(m*vx); 0,0,0,1; 0,(a*cf-b*cr)/(Iz*vx),-(a*cf-b*cr)/Iz,(a*a*cf+b*b*cr)/(Iz*vx)]; B=[0; -cf/m; 0; -a*cf/Iz]; Q=1*eye(4); R=10;
自己写的迭代函数:
`function [K2,P] = lqrtest(A, B, Qx, Ru) %-------------------------------------------------------------------------- % P matrix calculation: P=Qx; iteration_num=1; max_num_iteration=20000; tolerance = [0 0 0 0;0 1 1 1;0 1 1 1;0 1 1 1]; err = 2*ones(4,4); while(err >= tolerance & iteration_num < max_num_iteration) iteration_num=iteration_num+1; P_1 = Qx + A'*P*A - A'*P*B*(Ru+B'*P*B)^(-1)*B'*P*A; err = abs(P_1 - P); if sum(sum(isnan(P_1))) break; end P = P_1; end % gain K matrix calculation: K2 = inv(Ru + B'*P*B)*(B'*P*A); end
[k,P]=lqr(A,B,Q,R) % 使用matlab自带函数 和 [k,P]=lqrtest(A,B,Q,R) %使用迭代求解riccati方程求P
两种方法算出来的解是不一样的,那我用迭代法的解是不是就不可以啊?
The text was updated successfully, but these errors were encountered:
车参数: cf=-110000; cr=cf; m=2108; Iz=1585.3; a=1.47; b=2.97-a; k=zeros(1,4); i=1; vx=0.01*i; A=[1,1,0,0; 1,(cf+cr)/(m*vx),-(cf+cr)/m,(a*cf-b*cr)/(m*vx); 0,0,0,1; 0,(a*cf-b*cr)/(Iz*vx),-(a*cf-b*cr)/Iz,(a*a*cf+b*b*cr)/(Iz*vx)]; B=[0; -cf/m; 0; -a*cf/Iz]; Q=1*eye(4); R=10; 自己写的迭代函数: `function [K2,P] = lqrtest(A, B, Qx, Ru) %-------------------------------------------------------------------------- % P matrix calculation: P=Qx; iteration_num=1; max_num_iteration=20000; tolerance = [0 0 0 0;0 1 1 1;0 1 1 1;0 1 1 1]; err = 2*ones(4,4); while(err >= tolerance & iteration_num < max_num_iteration) iteration_num=iteration_num+1; P_1 = Qx + A'*P*A - A'*P*B*(Ru+B'*P*B)^(-1)*B'*P*A; err = abs(P_1 - P); if sum(sum(isnan(P_1))) break; end P = P_1; end % gain K matrix calculation: K2 = inv(Ru + B'*P*B)*(B'*P*A); end [k,P]=lqr(A,B,Q,R) % 使用matlab自带函数 和 [k,P]=lqrtest(A,B,Q,R) %使用迭代求解riccati方程求P 两种方法算出来的解是不一样的,那我用迭代法的解是不是就不可以啊?
你这个tolerance设置的太大了,求不到最优解,你尝试把tolerance 调成 10-4
Sorry, something went wrong.
No branches or pull requests
车参数:
自己写的迭代函数:
[k,P]=lqr(A,B,Q,R) % 使用matlab自带函数
和
[k,P]=lqrtest(A,B,Q,R) %使用迭代求解riccati方程求P
两种方法算出来的解是不一样的,那我用迭代法的解是不是就不可以啊?
The text was updated successfully, but these errors were encountered: