Questions about LQG with full information











up vote
0
down vote

favorite












I have implemented LQG in MATLAB software. But, now I do not know how to determine the value of optimal cost. Each way of calculating cost, returns a different value. Which one should I trust to compare with other methods? Moreover, the optimal trajectory (x) does not converge to zero as in LQR. This is my code.



 % Problem: minimize J = x[N]' P[N] x[N] + L[x,u]
% s.a. x[k+1] = A x[k] + B u[k] + w[k]
% where L[x,u] = sum{k=0}^{N-1} ( x[k]' Q x[k] + u[k]' R u[k] )

N = 50; % Horizon

% System Data
A = 1; B = 1; Q = 1; R = 1;
W = 1; P(:,:,N) = 1;
x(:,1) = 5;

% Calculate gain and Riccati
for k = N-1:-1:1
Aux1 = inv(R + B' * P(:,:,k+1) * B);
K(:,:,k) = - Aux1 * B' * P(:,:,k+1) * A;
Aux2 = P(:,:,k+1) - P(:,:,k+1) * B * Aux1 * B' * P(:,:,k+1);
P(:,:,k) = A' * Aux2 * A + Q;
end

% System Simulation
for i = 1:N-1
w = mvnrnd(0,W);
u(:,i) = K(:,:,i) * x(:,i);
x(:,i+1) = A * x(:,i) + B * u(:,i) + w;
if i == 1
J(i) = x(:,i)' * Q * x(:,i) + u(:,i)' * R * u(:,i);
else
J(i) = x(:,i)' * Q * x(:,i) + u(:,i)' * R * u(:,i) + J(i-1);
end
end

% Optimal Cost (calculated)
J_opt = J(N-1) + x(:,N)' * P(:,:,N) * x(:,N)

% Case I - Optimal Cost (Dynamic Programming)
Aux = 0;
for j = 1:N-1
Aux = Aux + trace( P(:,:,j+1) * W);
end
V = x(:,1)' * P(:,:,1) * x(:,1) + Aux

% Case II - Optimal Cost (Dynamic Programming)
X0 = cov( x(:,1) );
V2 = trace( P(:,:,1) * X0) + Aux


In addition, I looked for lectures to help me. But, I did not find a good teaching material. Could someone tell me one?










share|cite|improve this question







New contributor




Lara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    0
    down vote

    favorite












    I have implemented LQG in MATLAB software. But, now I do not know how to determine the value of optimal cost. Each way of calculating cost, returns a different value. Which one should I trust to compare with other methods? Moreover, the optimal trajectory (x) does not converge to zero as in LQR. This is my code.



     % Problem: minimize J = x[N]' P[N] x[N] + L[x,u]
    % s.a. x[k+1] = A x[k] + B u[k] + w[k]
    % where L[x,u] = sum{k=0}^{N-1} ( x[k]' Q x[k] + u[k]' R u[k] )

    N = 50; % Horizon

    % System Data
    A = 1; B = 1; Q = 1; R = 1;
    W = 1; P(:,:,N) = 1;
    x(:,1) = 5;

    % Calculate gain and Riccati
    for k = N-1:-1:1
    Aux1 = inv(R + B' * P(:,:,k+1) * B);
    K(:,:,k) = - Aux1 * B' * P(:,:,k+1) * A;
    Aux2 = P(:,:,k+1) - P(:,:,k+1) * B * Aux1 * B' * P(:,:,k+1);
    P(:,:,k) = A' * Aux2 * A + Q;
    end

    % System Simulation
    for i = 1:N-1
    w = mvnrnd(0,W);
    u(:,i) = K(:,:,i) * x(:,i);
    x(:,i+1) = A * x(:,i) + B * u(:,i) + w;
    if i == 1
    J(i) = x(:,i)' * Q * x(:,i) + u(:,i)' * R * u(:,i);
    else
    J(i) = x(:,i)' * Q * x(:,i) + u(:,i)' * R * u(:,i) + J(i-1);
    end
    end

    % Optimal Cost (calculated)
    J_opt = J(N-1) + x(:,N)' * P(:,:,N) * x(:,N)

    % Case I - Optimal Cost (Dynamic Programming)
    Aux = 0;
    for j = 1:N-1
    Aux = Aux + trace( P(:,:,j+1) * W);
    end
    V = x(:,1)' * P(:,:,1) * x(:,1) + Aux

    % Case II - Optimal Cost (Dynamic Programming)
    X0 = cov( x(:,1) );
    V2 = trace( P(:,:,1) * X0) + Aux


    In addition, I looked for lectures to help me. But, I did not find a good teaching material. Could someone tell me one?










    share|cite|improve this question







    New contributor




    Lara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have implemented LQG in MATLAB software. But, now I do not know how to determine the value of optimal cost. Each way of calculating cost, returns a different value. Which one should I trust to compare with other methods? Moreover, the optimal trajectory (x) does not converge to zero as in LQR. This is my code.



       % Problem: minimize J = x[N]' P[N] x[N] + L[x,u]
      % s.a. x[k+1] = A x[k] + B u[k] + w[k]
      % where L[x,u] = sum{k=0}^{N-1} ( x[k]' Q x[k] + u[k]' R u[k] )

      N = 50; % Horizon

      % System Data
      A = 1; B = 1; Q = 1; R = 1;
      W = 1; P(:,:,N) = 1;
      x(:,1) = 5;

      % Calculate gain and Riccati
      for k = N-1:-1:1
      Aux1 = inv(R + B' * P(:,:,k+1) * B);
      K(:,:,k) = - Aux1 * B' * P(:,:,k+1) * A;
      Aux2 = P(:,:,k+1) - P(:,:,k+1) * B * Aux1 * B' * P(:,:,k+1);
      P(:,:,k) = A' * Aux2 * A + Q;
      end

      % System Simulation
      for i = 1:N-1
      w = mvnrnd(0,W);
      u(:,i) = K(:,:,i) * x(:,i);
      x(:,i+1) = A * x(:,i) + B * u(:,i) + w;
      if i == 1
      J(i) = x(:,i)' * Q * x(:,i) + u(:,i)' * R * u(:,i);
      else
      J(i) = x(:,i)' * Q * x(:,i) + u(:,i)' * R * u(:,i) + J(i-1);
      end
      end

      % Optimal Cost (calculated)
      J_opt = J(N-1) + x(:,N)' * P(:,:,N) * x(:,N)

      % Case I - Optimal Cost (Dynamic Programming)
      Aux = 0;
      for j = 1:N-1
      Aux = Aux + trace( P(:,:,j+1) * W);
      end
      V = x(:,1)' * P(:,:,1) * x(:,1) + Aux

      % Case II - Optimal Cost (Dynamic Programming)
      X0 = cov( x(:,1) );
      V2 = trace( P(:,:,1) * X0) + Aux


      In addition, I looked for lectures to help me. But, I did not find a good teaching material. Could someone tell me one?










      share|cite|improve this question







      New contributor




      Lara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have implemented LQG in MATLAB software. But, now I do not know how to determine the value of optimal cost. Each way of calculating cost, returns a different value. Which one should I trust to compare with other methods? Moreover, the optimal trajectory (x) does not converge to zero as in LQR. This is my code.



       % Problem: minimize J = x[N]' P[N] x[N] + L[x,u]
      % s.a. x[k+1] = A x[k] + B u[k] + w[k]
      % where L[x,u] = sum{k=0}^{N-1} ( x[k]' Q x[k] + u[k]' R u[k] )

      N = 50; % Horizon

      % System Data
      A = 1; B = 1; Q = 1; R = 1;
      W = 1; P(:,:,N) = 1;
      x(:,1) = 5;

      % Calculate gain and Riccati
      for k = N-1:-1:1
      Aux1 = inv(R + B' * P(:,:,k+1) * B);
      K(:,:,k) = - Aux1 * B' * P(:,:,k+1) * A;
      Aux2 = P(:,:,k+1) - P(:,:,k+1) * B * Aux1 * B' * P(:,:,k+1);
      P(:,:,k) = A' * Aux2 * A + Q;
      end

      % System Simulation
      for i = 1:N-1
      w = mvnrnd(0,W);
      u(:,i) = K(:,:,i) * x(:,i);
      x(:,i+1) = A * x(:,i) + B * u(:,i) + w;
      if i == 1
      J(i) = x(:,i)' * Q * x(:,i) + u(:,i)' * R * u(:,i);
      else
      J(i) = x(:,i)' * Q * x(:,i) + u(:,i)' * R * u(:,i) + J(i-1);
      end
      end

      % Optimal Cost (calculated)
      J_opt = J(N-1) + x(:,N)' * P(:,:,N) * x(:,N)

      % Case I - Optimal Cost (Dynamic Programming)
      Aux = 0;
      for j = 1:N-1
      Aux = Aux + trace( P(:,:,j+1) * W);
      end
      V = x(:,1)' * P(:,:,1) * x(:,1) + Aux

      % Case II - Optimal Cost (Dynamic Programming)
      X0 = cov( x(:,1) );
      V2 = trace( P(:,:,1) * X0) + Aux


      In addition, I looked for lectures to help me. But, I did not find a good teaching material. Could someone tell me one?







      control-theory optimal-control linear-control






      share|cite|improve this question







      New contributor




      Lara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|cite|improve this question







      New contributor




      Lara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|cite|improve this question




      share|cite|improve this question






      New contributor




      Lara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Dec 1 at 1:26









      Lara

      1




      1




      New contributor




      Lara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Lara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Lara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Keep in mind that the first method uses one specific noise realization. For example think in the extreem when $N=1$, then it is possible that one noise sample is very close to or very far from zero. Only if you would simulate the system many times then the average should go towards an expected value.



          I am not sure where you got your expression for the optimal cost of Case II. Namely matlab will always return zero when evaluating cov( x(:,1) ) if the state dimension is zero.






          share|cite|improve this answer





















            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "69"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            noCode: true, onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            Lara is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3020889%2fquestions-about-lqg-with-full-information%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Keep in mind that the first method uses one specific noise realization. For example think in the extreem when $N=1$, then it is possible that one noise sample is very close to or very far from zero. Only if you would simulate the system many times then the average should go towards an expected value.



            I am not sure where you got your expression for the optimal cost of Case II. Namely matlab will always return zero when evaluating cov( x(:,1) ) if the state dimension is zero.






            share|cite|improve this answer

























              up vote
              0
              down vote













              Keep in mind that the first method uses one specific noise realization. For example think in the extreem when $N=1$, then it is possible that one noise sample is very close to or very far from zero. Only if you would simulate the system many times then the average should go towards an expected value.



              I am not sure where you got your expression for the optimal cost of Case II. Namely matlab will always return zero when evaluating cov( x(:,1) ) if the state dimension is zero.






              share|cite|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Keep in mind that the first method uses one specific noise realization. For example think in the extreem when $N=1$, then it is possible that one noise sample is very close to or very far from zero. Only if you would simulate the system many times then the average should go towards an expected value.



                I am not sure where you got your expression for the optimal cost of Case II. Namely matlab will always return zero when evaluating cov( x(:,1) ) if the state dimension is zero.






                share|cite|improve this answer












                Keep in mind that the first method uses one specific noise realization. For example think in the extreem when $N=1$, then it is possible that one noise sample is very close to or very far from zero. Only if you would simulate the system many times then the average should go towards an expected value.



                I am not sure where you got your expression for the optimal cost of Case II. Namely matlab will always return zero when evaluating cov( x(:,1) ) if the state dimension is zero.







                share|cite|improve this answer












                share|cite|improve this answer



                share|cite|improve this answer










                answered 2 days ago









                Kwin van der Veen

                5,1652826




                5,1652826






















                    Lara is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    Lara is a new contributor. Be nice, and check out our Code of Conduct.













                    Lara is a new contributor. Be nice, and check out our Code of Conduct.












                    Lara is a new contributor. Be nice, and check out our Code of Conduct.
















                    Thanks for contributing an answer to Mathematics Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3020889%2fquestions-about-lqg-with-full-information%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Måne

                    Storängen

                    VLT Carioca