Skip to content
New issue

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

Update DARE #173

Merged
merged 3 commits into from
Oct 30, 2019
Merged

Update DARE #173

merged 3 commits into from
Oct 30, 2019

Conversation

HppyCtrlEngnrng
Copy link
Contributor

Remove the assumption of invertibility of A matrix utilizing generalized Schur decomposition.

@coveralls
Copy link

coveralls commented Jan 16, 2019

Coverage Status

Coverage increased (+0.002%) to 54.361% when pulling baa0285 on HppyCtrlEngnrng:dare into 9803d0e on JuliaControl:master.

@baggepinnen
Copy link
Member

Looks good to me, @mfalt?

Copy link
Member

@mfalt mfalt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should at least have a simple test for when the old code didn't work.
I am not sure i follow the code, do we have proper tests for care already?

B*inv(R)*B'
catch
error("R must be non-singular.")
if (minimum(eigvals(Q)) < 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when eigvals are complex here?

@olof3
Copy link
Contributor

olof3 commented Jan 29, 2019

Great! However two test cases where the new code breaks and the old code worked are

I2 = Matrix{Float64}(I, 2, 2)
dare([1.0 im; im 1.0], I2, I2, I2) ≈ [1 + sqrt(2) 0; 0 1 + sqrt(2)]
dare(1.0, 1, 1, 1) ≈ fill((1 + sqrt(5))/2, 1, 1)

The first test case is fixed by changing transpose(A) to A' and transpose(B) to B'. (Laub's paper only considered the real case, but the complex case is roughly the same, see Lancaster's book on Algebraic Riccatti equations).

The second test case still breaks since somehow the new code doesn't handle scalar inputs due to that
[1.0I 1; 0.0 1.0] gives a matrix of type Any!? Somehow this was not an issue in the old code. It can be discussed if it is necessary to support scalar inputs.

Two other test cases which would be good to include are

dare(1.0im, 1, 1, 1) ≈ fill((1 + sqrt(5))/2, 1, 1)
dare(1.0, 1im, 1, 1) ≈ fill((1 + sqrt(5))/2, 1, 1)

Support complex/scalar A, B, Q, R.
@HppyCtrlEngnrng
Copy link
Contributor Author

Dear All, Thank you very much for your reviews!
As you pointed out, I focused only on real case for discrete time LQR.
Now, I made some updates and it supports both complex and scalar A, B, Q, R.

Also, I wrote a few test codes.
Could you please check them out?
dare_update_tests.zip

@@ -34,37 +34,35 @@ end
"""`dare(A, B, Q, R)`

Compute `X`, the solution to the discrete-time algebraic Riccati equation,
defined as A'XA - X - (A'XB)(B'XB + R)^-1(B'XA) + Q = 0, where A and R
are non-singular.
defined as A'XA - X - (A'XB)(B'XB + R)^-1(B'XA) + Q = 0, where Q>=0 and R>0

Algorithm taken from:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need updating now?

n = size(A, 1);

E = [
Matrix{Float64}(I, n, n) B/R*B';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Matrix{Float64}(I, n, n) B/R*B';
I B/R*B';

shouldn't it be enough to write I?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a bug in julia where this didn't work for 0 size of I. We could test it against 1.0.x to see if the proposed change works, but I don't see a problem in leaving it like this.

];
F = [
A zeros(size(A));
-Q Matrix{Float64}(I, n, n)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-Q Matrix{Float64}(I, n, n)
-Q I

same here?

@mfalt mfalt added this to the 0.5.4 milestone Oct 29, 2019
@mfalt mfalt mentioned this pull request Oct 30, 2019
@mfalt mfalt merged commit baa0285 into JuliaControl:master Oct 30, 2019
@mfalt
Copy link
Member

mfalt commented Oct 30, 2019

Thanks for fixing this @HppyCtrlEngnrng

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants