Aproximate Double Integral Result Using The Monte Carlo Method Getting 2 different results












0












$begingroup$


My task is to approximate a result using the Monte Carlo method programatically.
The integral in question is the following:
$iint (2x+y) dxdy$



The integral is delimited by the graph axes (xOy) and by the segment x+y=3.
From the last line I've deduced that the interval for x is [0,3] and for y is [0,3] obtaining some kind of triangle that has the vertices on (0,0), (0,3) and (3,0).



What I've tried so far yielded the following results:



$int^3_0int^3_0 (2x+y) dxdy = int^3_0 (x^2+xy)dy$



Then I've replaced x with the limit ends for it (3,0):



$int^3_0 (x^2+xy)dy = int^3_0 (9+3y) - 0dy$



Then I proceeded to calculate the integral by y.



$int^3_0 (9+3y)dy = 9y+(3y^2)/2$



Then I've replaced the y with the limit terms (3,0):



$9*3+(3*9)/2 - 0 = 27 + 27/2 = 27 + 13,5 = 40,5$



So the final result that I got by manually integrating was 40,5.



Then I tried to aproximate this result using C#, but I'll write in pseudocode:



sum=0
for i->number_of_iterations
x = random between 0 and 3
y = random between 0 and 3 - x
sum = sum + 2 * x + y
end for
sum = sum * (xUpperLimit-xLowerLimit) * (yUpperLimit - yLowerLimit) / number_of_iterations


However, the result that it tends to converge to is 33,75.
What am I doing wrong?
And, is the interval that I've deduced for x and y even the right one?










share|cite|improve this question











$endgroup$












  • $begingroup$
    You should compute $$int_0^3 int_0^{3-y} (2x+y) dx dy = int_0^3 ((3-y)^2-(3-y)y) dy$$
    $endgroup$
    – Crostul
    Dec 26 '18 at 11:03
















0












$begingroup$


My task is to approximate a result using the Monte Carlo method programatically.
The integral in question is the following:
$iint (2x+y) dxdy$



The integral is delimited by the graph axes (xOy) and by the segment x+y=3.
From the last line I've deduced that the interval for x is [0,3] and for y is [0,3] obtaining some kind of triangle that has the vertices on (0,0), (0,3) and (3,0).



What I've tried so far yielded the following results:



$int^3_0int^3_0 (2x+y) dxdy = int^3_0 (x^2+xy)dy$



Then I've replaced x with the limit ends for it (3,0):



$int^3_0 (x^2+xy)dy = int^3_0 (9+3y) - 0dy$



Then I proceeded to calculate the integral by y.



$int^3_0 (9+3y)dy = 9y+(3y^2)/2$



Then I've replaced the y with the limit terms (3,0):



$9*3+(3*9)/2 - 0 = 27 + 27/2 = 27 + 13,5 = 40,5$



So the final result that I got by manually integrating was 40,5.



Then I tried to aproximate this result using C#, but I'll write in pseudocode:



sum=0
for i->number_of_iterations
x = random between 0 and 3
y = random between 0 and 3 - x
sum = sum + 2 * x + y
end for
sum = sum * (xUpperLimit-xLowerLimit) * (yUpperLimit - yLowerLimit) / number_of_iterations


However, the result that it tends to converge to is 33,75.
What am I doing wrong?
And, is the interval that I've deduced for x and y even the right one?










share|cite|improve this question











$endgroup$












  • $begingroup$
    You should compute $$int_0^3 int_0^{3-y} (2x+y) dx dy = int_0^3 ((3-y)^2-(3-y)y) dy$$
    $endgroup$
    – Crostul
    Dec 26 '18 at 11:03














0












0








0





$begingroup$


My task is to approximate a result using the Monte Carlo method programatically.
The integral in question is the following:
$iint (2x+y) dxdy$



The integral is delimited by the graph axes (xOy) and by the segment x+y=3.
From the last line I've deduced that the interval for x is [0,3] and for y is [0,3] obtaining some kind of triangle that has the vertices on (0,0), (0,3) and (3,0).



What I've tried so far yielded the following results:



$int^3_0int^3_0 (2x+y) dxdy = int^3_0 (x^2+xy)dy$



Then I've replaced x with the limit ends for it (3,0):



$int^3_0 (x^2+xy)dy = int^3_0 (9+3y) - 0dy$



Then I proceeded to calculate the integral by y.



$int^3_0 (9+3y)dy = 9y+(3y^2)/2$



Then I've replaced the y with the limit terms (3,0):



$9*3+(3*9)/2 - 0 = 27 + 27/2 = 27 + 13,5 = 40,5$



So the final result that I got by manually integrating was 40,5.



Then I tried to aproximate this result using C#, but I'll write in pseudocode:



sum=0
for i->number_of_iterations
x = random between 0 and 3
y = random between 0 and 3 - x
sum = sum + 2 * x + y
end for
sum = sum * (xUpperLimit-xLowerLimit) * (yUpperLimit - yLowerLimit) / number_of_iterations


However, the result that it tends to converge to is 33,75.
What am I doing wrong?
And, is the interval that I've deduced for x and y even the right one?










share|cite|improve this question











$endgroup$




My task is to approximate a result using the Monte Carlo method programatically.
The integral in question is the following:
$iint (2x+y) dxdy$



The integral is delimited by the graph axes (xOy) and by the segment x+y=3.
From the last line I've deduced that the interval for x is [0,3] and for y is [0,3] obtaining some kind of triangle that has the vertices on (0,0), (0,3) and (3,0).



What I've tried so far yielded the following results:



$int^3_0int^3_0 (2x+y) dxdy = int^3_0 (x^2+xy)dy$



Then I've replaced x with the limit ends for it (3,0):



$int^3_0 (x^2+xy)dy = int^3_0 (9+3y) - 0dy$



Then I proceeded to calculate the integral by y.



$int^3_0 (9+3y)dy = 9y+(3y^2)/2$



Then I've replaced the y with the limit terms (3,0):



$9*3+(3*9)/2 - 0 = 27 + 27/2 = 27 + 13,5 = 40,5$



So the final result that I got by manually integrating was 40,5.



Then I tried to aproximate this result using C#, but I'll write in pseudocode:



sum=0
for i->number_of_iterations
x = random between 0 and 3
y = random between 0 and 3 - x
sum = sum + 2 * x + y
end for
sum = sum * (xUpperLimit-xLowerLimit) * (yUpperLimit - yLowerLimit) / number_of_iterations


However, the result that it tends to converge to is 33,75.
What am I doing wrong?
And, is the interval that I've deduced for x and y even the right one?







calculus integration multivariable-calculus






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Dec 26 '18 at 11:25









Key Flex

8,58761233




8,58761233










asked Dec 26 '18 at 10:56









Bărhălescu Vlad FlorianBărhălescu Vlad Florian

32




32












  • $begingroup$
    You should compute $$int_0^3 int_0^{3-y} (2x+y) dx dy = int_0^3 ((3-y)^2-(3-y)y) dy$$
    $endgroup$
    – Crostul
    Dec 26 '18 at 11:03


















  • $begingroup$
    You should compute $$int_0^3 int_0^{3-y} (2x+y) dx dy = int_0^3 ((3-y)^2-(3-y)y) dy$$
    $endgroup$
    – Crostul
    Dec 26 '18 at 11:03
















$begingroup$
You should compute $$int_0^3 int_0^{3-y} (2x+y) dx dy = int_0^3 ((3-y)^2-(3-y)y) dy$$
$endgroup$
– Crostul
Dec 26 '18 at 11:03




$begingroup$
You should compute $$int_0^3 int_0^{3-y} (2x+y) dx dy = int_0^3 ((3-y)^2-(3-y)y) dy$$
$endgroup$
– Crostul
Dec 26 '18 at 11:03










1 Answer
1






active

oldest

votes


















1












$begingroup$

You are choosing $x$ from a uniform distribution on $[0,3]$, but this is wrong: over the triangle of integration, $x$ is more likely to be small than large. This is the source of your error.



You have to choose a point $(x,y)$ from a uniform distribution over the triangle of integration. The simplest way is to choose $x$ and $y$ separately from uniform distibutions over $[0,3]$, and reject those $(x,y)$ pairs with $x+y>3$. Or to avoid waste, instead of rejecting such pairs you can use $(3-x,3-y)$ instead.






share|cite|improve this answer









$endgroup$













    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',
    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
    },
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3052833%2faproximate-double-integral-result-using-the-monte-carlo-method-getting-2-differe%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









    1












    $begingroup$

    You are choosing $x$ from a uniform distribution on $[0,3]$, but this is wrong: over the triangle of integration, $x$ is more likely to be small than large. This is the source of your error.



    You have to choose a point $(x,y)$ from a uniform distribution over the triangle of integration. The simplest way is to choose $x$ and $y$ separately from uniform distibutions over $[0,3]$, and reject those $(x,y)$ pairs with $x+y>3$. Or to avoid waste, instead of rejecting such pairs you can use $(3-x,3-y)$ instead.






    share|cite|improve this answer









    $endgroup$


















      1












      $begingroup$

      You are choosing $x$ from a uniform distribution on $[0,3]$, but this is wrong: over the triangle of integration, $x$ is more likely to be small than large. This is the source of your error.



      You have to choose a point $(x,y)$ from a uniform distribution over the triangle of integration. The simplest way is to choose $x$ and $y$ separately from uniform distibutions over $[0,3]$, and reject those $(x,y)$ pairs with $x+y>3$. Or to avoid waste, instead of rejecting such pairs you can use $(3-x,3-y)$ instead.






      share|cite|improve this answer









      $endgroup$
















        1












        1








        1





        $begingroup$

        You are choosing $x$ from a uniform distribution on $[0,3]$, but this is wrong: over the triangle of integration, $x$ is more likely to be small than large. This is the source of your error.



        You have to choose a point $(x,y)$ from a uniform distribution over the triangle of integration. The simplest way is to choose $x$ and $y$ separately from uniform distibutions over $[0,3]$, and reject those $(x,y)$ pairs with $x+y>3$. Or to avoid waste, instead of rejecting such pairs you can use $(3-x,3-y)$ instead.






        share|cite|improve this answer









        $endgroup$



        You are choosing $x$ from a uniform distribution on $[0,3]$, but this is wrong: over the triangle of integration, $x$ is more likely to be small than large. This is the source of your error.



        You have to choose a point $(x,y)$ from a uniform distribution over the triangle of integration. The simplest way is to choose $x$ and $y$ separately from uniform distibutions over $[0,3]$, and reject those $(x,y)$ pairs with $x+y>3$. Or to avoid waste, instead of rejecting such pairs you can use $(3-x,3-y)$ instead.







        share|cite|improve this answer












        share|cite|improve this answer



        share|cite|improve this answer










        answered Dec 26 '18 at 11:20









        TonyKTonyK

        43.1k356135




        43.1k356135






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3052833%2faproximate-double-integral-result-using-the-monte-carlo-method-getting-2-differe%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

            Probability when a professor distributes a quiz and homework assignment to a class of n students.

            Aardman Animations

            Are they similar matrix