Surface Plot of Multivariate Normal Density












0















I have a likelihood function with Multivariate Normal Density whose mean is mu=[3 5]' and covariance=9*I. How can I plot its 2D surface in Matlab?










share|improve this question





























    0















    I have a likelihood function with Multivariate Normal Density whose mean is mu=[3 5]' and covariance=9*I. How can I plot its 2D surface in Matlab?










    share|improve this question



























      0












      0








      0








      I have a likelihood function with Multivariate Normal Density whose mean is mu=[3 5]' and covariance=9*I. How can I plot its 2D surface in Matlab?










      share|improve this question
















      I have a likelihood function with Multivariate Normal Density whose mean is mu=[3 5]' and covariance=9*I. How can I plot its 2D surface in Matlab?







      matlab normal-distribution probability-density






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 27 at 7:44









      SecretAgentMan

      718316




      718316










      asked Nov 27 '18 at 23:14









      john greenjohn green

      11




      11
























          2 Answers
          2






          active

          oldest

          votes


















          0














          The log-likelihood function can be obtained from the PDF or by referencing the wiki.



          Mu = [3 5]';
          Sigma = 9*eye(2);
          loglikeh=@(x) -0.5*log(det(Sigma)) + (x-Mu)'*inv(Sigma)*(x-Mu) + length(x)*log(2*pi); % For single x

          xMin = -2;
          xMax = 7;
          step = 0.1;
          X1 = xMin:step:xMax;
          X2 = xMin:step:xMax;
          L = zeros(length(X1),length(X2));
          for i = 1:length(X1)
          for j = 1:length(X2)
          x = [X1(i) X2(j)]';
          L(i,j) = loglikeh(x);
          end
          end


          If I've made a mistake, please comment so I can fix. Hope this helps.



          Plotting



          surf(X1,X2,L')      % Note L is transposed if done this way
          xlabel('x_1')
          ylabel('x_2')
          zlabel('log-likelihood')


          See these answers for more visualizations and options.






          share|improve this answer































            -1














            You may try to refer in here:
            (use mvnpdf function in MATLAB)
            F = mvnpdf([X1(:) X2(:)],mu,Sigma)
            Please check here https://www.mathworks.com/help/stats/multivariate-normal-distribution.html






            share|improve this answer
























            • The multivariate Normal probability density function (PDF) and likelihood function are not the same thing. See here

              – SecretAgentMan
              Nov 28 '18 at 14:55











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            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',
            autoActivateHeartbeat: false,
            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
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53509675%2fsurface-plot-of-multivariate-normal-density%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The log-likelihood function can be obtained from the PDF or by referencing the wiki.



            Mu = [3 5]';
            Sigma = 9*eye(2);
            loglikeh=@(x) -0.5*log(det(Sigma)) + (x-Mu)'*inv(Sigma)*(x-Mu) + length(x)*log(2*pi); % For single x

            xMin = -2;
            xMax = 7;
            step = 0.1;
            X1 = xMin:step:xMax;
            X2 = xMin:step:xMax;
            L = zeros(length(X1),length(X2));
            for i = 1:length(X1)
            for j = 1:length(X2)
            x = [X1(i) X2(j)]';
            L(i,j) = loglikeh(x);
            end
            end


            If I've made a mistake, please comment so I can fix. Hope this helps.



            Plotting



            surf(X1,X2,L')      % Note L is transposed if done this way
            xlabel('x_1')
            ylabel('x_2')
            zlabel('log-likelihood')


            See these answers for more visualizations and options.






            share|improve this answer




























              0














              The log-likelihood function can be obtained from the PDF or by referencing the wiki.



              Mu = [3 5]';
              Sigma = 9*eye(2);
              loglikeh=@(x) -0.5*log(det(Sigma)) + (x-Mu)'*inv(Sigma)*(x-Mu) + length(x)*log(2*pi); % For single x

              xMin = -2;
              xMax = 7;
              step = 0.1;
              X1 = xMin:step:xMax;
              X2 = xMin:step:xMax;
              L = zeros(length(X1),length(X2));
              for i = 1:length(X1)
              for j = 1:length(X2)
              x = [X1(i) X2(j)]';
              L(i,j) = loglikeh(x);
              end
              end


              If I've made a mistake, please comment so I can fix. Hope this helps.



              Plotting



              surf(X1,X2,L')      % Note L is transposed if done this way
              xlabel('x_1')
              ylabel('x_2')
              zlabel('log-likelihood')


              See these answers for more visualizations and options.






              share|improve this answer


























                0












                0








                0







                The log-likelihood function can be obtained from the PDF or by referencing the wiki.



                Mu = [3 5]';
                Sigma = 9*eye(2);
                loglikeh=@(x) -0.5*log(det(Sigma)) + (x-Mu)'*inv(Sigma)*(x-Mu) + length(x)*log(2*pi); % For single x

                xMin = -2;
                xMax = 7;
                step = 0.1;
                X1 = xMin:step:xMax;
                X2 = xMin:step:xMax;
                L = zeros(length(X1),length(X2));
                for i = 1:length(X1)
                for j = 1:length(X2)
                x = [X1(i) X2(j)]';
                L(i,j) = loglikeh(x);
                end
                end


                If I've made a mistake, please comment so I can fix. Hope this helps.



                Plotting



                surf(X1,X2,L')      % Note L is transposed if done this way
                xlabel('x_1')
                ylabel('x_2')
                zlabel('log-likelihood')


                See these answers for more visualizations and options.






                share|improve this answer













                The log-likelihood function can be obtained from the PDF or by referencing the wiki.



                Mu = [3 5]';
                Sigma = 9*eye(2);
                loglikeh=@(x) -0.5*log(det(Sigma)) + (x-Mu)'*inv(Sigma)*(x-Mu) + length(x)*log(2*pi); % For single x

                xMin = -2;
                xMax = 7;
                step = 0.1;
                X1 = xMin:step:xMax;
                X2 = xMin:step:xMax;
                L = zeros(length(X1),length(X2));
                for i = 1:length(X1)
                for j = 1:length(X2)
                x = [X1(i) X2(j)]';
                L(i,j) = loglikeh(x);
                end
                end


                If I've made a mistake, please comment so I can fix. Hope this helps.



                Plotting



                surf(X1,X2,L')      % Note L is transposed if done this way
                xlabel('x_1')
                ylabel('x_2')
                zlabel('log-likelihood')


                See these answers for more visualizations and options.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 28 '18 at 15:13









                SecretAgentManSecretAgentMan

                718316




                718316

























                    -1














                    You may try to refer in here:
                    (use mvnpdf function in MATLAB)
                    F = mvnpdf([X1(:) X2(:)],mu,Sigma)
                    Please check here https://www.mathworks.com/help/stats/multivariate-normal-distribution.html






                    share|improve this answer
























                    • The multivariate Normal probability density function (PDF) and likelihood function are not the same thing. See here

                      – SecretAgentMan
                      Nov 28 '18 at 14:55
















                    -1














                    You may try to refer in here:
                    (use mvnpdf function in MATLAB)
                    F = mvnpdf([X1(:) X2(:)],mu,Sigma)
                    Please check here https://www.mathworks.com/help/stats/multivariate-normal-distribution.html






                    share|improve this answer
























                    • The multivariate Normal probability density function (PDF) and likelihood function are not the same thing. See here

                      – SecretAgentMan
                      Nov 28 '18 at 14:55














                    -1












                    -1








                    -1







                    You may try to refer in here:
                    (use mvnpdf function in MATLAB)
                    F = mvnpdf([X1(:) X2(:)],mu,Sigma)
                    Please check here https://www.mathworks.com/help/stats/multivariate-normal-distribution.html






                    share|improve this answer













                    You may try to refer in here:
                    (use mvnpdf function in MATLAB)
                    F = mvnpdf([X1(:) X2(:)],mu,Sigma)
                    Please check here https://www.mathworks.com/help/stats/multivariate-normal-distribution.html







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 28 '18 at 1:10









                    A. SyamA. Syam

                    113119




                    113119













                    • The multivariate Normal probability density function (PDF) and likelihood function are not the same thing. See here

                      – SecretAgentMan
                      Nov 28 '18 at 14:55



















                    • The multivariate Normal probability density function (PDF) and likelihood function are not the same thing. See here

                      – SecretAgentMan
                      Nov 28 '18 at 14:55

















                    The multivariate Normal probability density function (PDF) and likelihood function are not the same thing. See here

                    – SecretAgentMan
                    Nov 28 '18 at 14:55





                    The multivariate Normal probability density function (PDF) and likelihood function are not the same thing. See here

                    – SecretAgentMan
                    Nov 28 '18 at 14:55


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • 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%2fstackoverflow.com%2fquestions%2f53509675%2fsurface-plot-of-multivariate-normal-density%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

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)