How to program numerical integration $int_t^{infty}frac{1}{(u+1)^2}du$?












0












$begingroup$


I'm facing a problem when program the numerical integration of $int_t^{infty}frac{1}{(u+1)^2}du$, I know that the true value is $frac{1}{1+t}$, however, when I want to calculate the definite integration numerically, I found the result is very strange like following:



image



The blue curve is the true value, the red curve is the numerical integration.



The problem setup is that I know $X_1,X_2,cdots,X_n$ (ranges from $0$ to $1$), then I tried to program following code in matlab:



((1./(1+Xi_sort).^2).*(Xi_sort-[0;Xi_sort(1:n-1)]))'*tril(ones(n,n),0)


What's wrong with this? Thank you so much for your help.










share|cite|improve this question











$endgroup$












  • $begingroup$
    Could you post all the code you use instead of just a piece of it?
    $endgroup$
    – user587192
    Dec 7 '18 at 2:57








  • 1




    $begingroup$
    The red one is the integral from $t$ to $1$, not $infty$
    $endgroup$
    – Empy2
    Dec 7 '18 at 3:35










  • $begingroup$
    @Empy2 I see, thank you. But I cannot change the range of $X_1$ to $X_2$, how can I remedy this in code? Will interpolation work?
    $endgroup$
    – caslp
    Dec 7 '18 at 4:02
















0












$begingroup$


I'm facing a problem when program the numerical integration of $int_t^{infty}frac{1}{(u+1)^2}du$, I know that the true value is $frac{1}{1+t}$, however, when I want to calculate the definite integration numerically, I found the result is very strange like following:



image



The blue curve is the true value, the red curve is the numerical integration.



The problem setup is that I know $X_1,X_2,cdots,X_n$ (ranges from $0$ to $1$), then I tried to program following code in matlab:



((1./(1+Xi_sort).^2).*(Xi_sort-[0;Xi_sort(1:n-1)]))'*tril(ones(n,n),0)


What's wrong with this? Thank you so much for your help.










share|cite|improve this question











$endgroup$












  • $begingroup$
    Could you post all the code you use instead of just a piece of it?
    $endgroup$
    – user587192
    Dec 7 '18 at 2:57








  • 1




    $begingroup$
    The red one is the integral from $t$ to $1$, not $infty$
    $endgroup$
    – Empy2
    Dec 7 '18 at 3:35










  • $begingroup$
    @Empy2 I see, thank you. But I cannot change the range of $X_1$ to $X_2$, how can I remedy this in code? Will interpolation work?
    $endgroup$
    – caslp
    Dec 7 '18 at 4:02














0












0








0





$begingroup$


I'm facing a problem when program the numerical integration of $int_t^{infty}frac{1}{(u+1)^2}du$, I know that the true value is $frac{1}{1+t}$, however, when I want to calculate the definite integration numerically, I found the result is very strange like following:



image



The blue curve is the true value, the red curve is the numerical integration.



The problem setup is that I know $X_1,X_2,cdots,X_n$ (ranges from $0$ to $1$), then I tried to program following code in matlab:



((1./(1+Xi_sort).^2).*(Xi_sort-[0;Xi_sort(1:n-1)]))'*tril(ones(n,n),0)


What's wrong with this? Thank you so much for your help.










share|cite|improve this question











$endgroup$




I'm facing a problem when program the numerical integration of $int_t^{infty}frac{1}{(u+1)^2}du$, I know that the true value is $frac{1}{1+t}$, however, when I want to calculate the definite integration numerically, I found the result is very strange like following:



image



The blue curve is the true value, the red curve is the numerical integration.



The problem setup is that I know $X_1,X_2,cdots,X_n$ (ranges from $0$ to $1$), then I tried to program following code in matlab:



((1./(1+Xi_sort).^2).*(Xi_sort-[0;Xi_sort(1:n-1)]))'*tril(ones(n,n),0)


What's wrong with this? Thank you so much for your help.







matlab numerical-calculus






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Dec 7 '18 at 3:08









user587192

1,841315




1,841315










asked Dec 7 '18 at 1:09









caslpcaslp

42




42












  • $begingroup$
    Could you post all the code you use instead of just a piece of it?
    $endgroup$
    – user587192
    Dec 7 '18 at 2:57








  • 1




    $begingroup$
    The red one is the integral from $t$ to $1$, not $infty$
    $endgroup$
    – Empy2
    Dec 7 '18 at 3:35










  • $begingroup$
    @Empy2 I see, thank you. But I cannot change the range of $X_1$ to $X_2$, how can I remedy this in code? Will interpolation work?
    $endgroup$
    – caslp
    Dec 7 '18 at 4:02


















  • $begingroup$
    Could you post all the code you use instead of just a piece of it?
    $endgroup$
    – user587192
    Dec 7 '18 at 2:57








  • 1




    $begingroup$
    The red one is the integral from $t$ to $1$, not $infty$
    $endgroup$
    – Empy2
    Dec 7 '18 at 3:35










  • $begingroup$
    @Empy2 I see, thank you. But I cannot change the range of $X_1$ to $X_2$, how can I remedy this in code? Will interpolation work?
    $endgroup$
    – caslp
    Dec 7 '18 at 4:02
















$begingroup$
Could you post all the code you use instead of just a piece of it?
$endgroup$
– user587192
Dec 7 '18 at 2:57






$begingroup$
Could you post all the code you use instead of just a piece of it?
$endgroup$
– user587192
Dec 7 '18 at 2:57






1




1




$begingroup$
The red one is the integral from $t$ to $1$, not $infty$
$endgroup$
– Empy2
Dec 7 '18 at 3:35




$begingroup$
The red one is the integral from $t$ to $1$, not $infty$
$endgroup$
– Empy2
Dec 7 '18 at 3:35












$begingroup$
@Empy2 I see, thank you. But I cannot change the range of $X_1$ to $X_2$, how can I remedy this in code? Will interpolation work?
$endgroup$
– caslp
Dec 7 '18 at 4:02




$begingroup$
@Empy2 I see, thank you. But I cannot change the range of $X_1$ to $X_2$, how can I remedy this in code? Will interpolation work?
$endgroup$
– caslp
Dec 7 '18 at 4:02










0






active

oldest

votes











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%2f3029321%2fhow-to-program-numerical-integration-int-t-infty-frac1u12du%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f3029321%2fhow-to-program-numerical-integration-int-t-infty-frac1u12du%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

Ellipse (mathématiques)

Quarter-circle Tiles

Mont Emei