Integral returning infinity for a definite integral with a finite value

조회 수: 3 (최근 30일)
Jack Joynson
Jack Joynson 2018년 12월 8일
답변: Star Strider 2018년 12월 8일
Hi,
I am trying to calculate an integral in a loop however it is just returning infinity for every value; The integral in question is finite - I have tested it in wolfram alpha.
Here is my code:
ytheory = 1:10;
s = 14;
func = @(L) s.^(-0.3) .* L.^(-0.7) .*exp(-L./s);
for(i = 1:10)
ytheory(i) = integral(func,0,i);
end
Is this an issue with Matlab or am I doing something wrong here?
Cheers

답변 (1개)

Star Strider
Star Strider 2018년 12월 8일
I can’t reproduce that in R2018b.
Your code works as expected:
s = 14;
func = @(L) s.^(-0.3) .* L.^(-0.7) .*exp(-L./s);
for i = 1:10
ytheory(i) = integral(func,0,i);
end
producing:
ytheory =
1.4858 1.8004 2.0019 2.1496 2.2646 2.3576 2.4346 2.4994 2.5547 2.6023

카테고리

Help CenterFile Exchange에서 External Language Interfaces에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by