이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to solve for limit of double integral
조회 수: 2 (최근 30일)
이전 댓글 표시
I am new to MATLAB. Please help me. I want to solve for the limit of double integral.
syms u x
a = 5;
b = 0.2;
c = 10;
d = 0.1;
k=0.01;
m = 1./(2.^(a+c-1).*gamma(a).*gamma(c).*b.^a.*d.^c);
h(u,x) = m.*(u+x).^(a-1).*(u-x).^(c-1).*exp(-(u+x)./(2.*b)-(u-x)./(2.*d));
f(x) = int(h,u,abs(x), inf);
solPk = fzero(@(Pk) integral(f,-inf,Pk)-k,[-10,10]);
Thank you so much.
채택된 답변
Walter Roberson
2018년 4월 30일
solPk = vpasolve(int(f,x,-inf,Pk) == k)
There is a closed form integral, but MATLAB is not able to find it. It is
piecewise(Pk < 0, -(770558495002939/5159780352000000000000)*exp(10*Pk)*(75937500*Pk^9-296156250*Pk^8+601425000*Pk^7-817897500*Pk^6+808258500*Pk^5-594641250*Pk^4+322528500*Pk^3-123369750*Pk^2+29996190*Pk-3512131), ...
0 <= Pk, 1310719999999999239/1310720000000000000+(1/25798901760000000000000)*(-11650844444444437680000*Pk^4-40389594074074050624000*Pk^3-58409566814814780902400*Pk^2-41590925590123432642560*Pk-12267389871934149256192)*exp(-5*Pk))
You could fzero() or fsolve() on that after making a guess about whether Pk will be positive or negative.
댓글 수: 25
Mikie
2018년 4월 30일
So, we are solving this problem with symbolic, right? I have a question. Can we solve this by numeric computation? How?
Thank you.
Walter Roberson
2018년 4월 30일
syms u x
a = 5;
b = 0.2;
c = 10;
d = 0.1;
k=0.01;
m = 1./(2.^(a+c-1).*gamma(a).*gamma(c).*b.^a.*d.^c);
h(u,x) = m.*(u+x).^(a-1).*(u-x).^(c-1).*exp(-(u+x)./(2.*b)-(u-x)./(2.*d));
f = matlabFunction(int(h,u,abs(x), inf));
solPk = fzero(@(Pk) integral(f,-inf,Pk)-k,[-10,10]);
It looks to me as if the function it produces is not correct for positive values, but it happens that for your purposes you do not need positive values.
Mikie
2018년 4월 30일
I have one more question. Why when
a = 30;
b = 0.2;
c = 20;
d = 0.1;
I cannot solve for solPk? It tells me that
Warning: Infinite or Not-a-Number value encountered.
> In integralCalc/iterateScalarValued (line 349)
In integralCalc/vadapt (line 132)
In integralCalc (line 91)
In integral (line 88)
In @(Pk)integral(f,-inf,Pk)-k
In fzero (line 230)
In Percentile3FnNSH (line 42)
Warning: Infinite or Not-a-Number value encountered.
> In integralCalc/iterateScalarValued (line 349)
In integralCalc/vadapt (line 132)
In integralCalc (line 91)
In integral (line 88)
In @(Pk)integral(f,-inf,Pk)-k
In fzero (line 240)
In Percentile3FnNSH (line 42)
Error using fzero (line 242)
Function values at interval endpoints must be finite and real.
Error in Percentile3FnNSH (line 42)
solPk = fzero(@(Pk) integral(f,-inf,Pk)-k,[-10,10])
Walter Roberson
2018년 5월 1일
The solution for that system is positive; it is possible that the integral is getting confused.
I would suggest that you split the integral at 0:
syms u x pk
a = 30;
b = 0.2;
c = 20;
d = 0.1;
k = 0.01;
m = 1./(2.^(a+c-1).*gamma(a).*gamma(c).*b.^a.*d.^c);
h(u,x) = m.*(u+x).^(a-1).*(u-x).^(c-1).*exp(-(u+x)./(2.*b)-(u-x)./(2.*d));
syms xm negative
syms xp positive
fm = int(h(u,xm),u,-xm, inf); %xm is negative so -xm is abs(xm)
intm = int(fm, xm, -inf, xm);
int0 = subs(intm, xm, 0);
if int0 > k
solpk = vpasolve(intm - k);
else
fp = int(h(u,xp),u,xp,inf); %xp is positive so xp is abs(xp)
intp = int(fp, xp, 0, xp);
solpk = vpasolve(intp + int0 == k);
end
This should in theory be able to handle both cases, provided that MATLAB can get the integral right given the hint about whether x is positive or negative.
Mikie
2018년 5월 1일
Sorry, I mean the solution can be either positive or negative. I am so sorry. It's my bad. But why when I run the code didn't it give me any solution in case of a = 30; b = 0.2; c = 20; d = 0.1.
Mikie
2018년 5월 1일
Could you give me any suggestion how to deal with this? This following happens when a = 30; b = 0.2; c = 20; d = 0.1 and when a = 25; b = 0.2; c = 40; d = 0.1. Thank you.
Warning: Infinite or Not-a-Number value encountered.
> In integralCalc/iterateScalarValued (line 349)
In integralCalc/vadapt (line 132)
In integralCalc (line 91)
In integral (line 88)
In Percentile3FnNSH>@(Pk)integral(f,-inf,Pk)-k
In fzero (line 228)
In Percentile3FnNSH (line 30)
Warning: Infinite or Not-a-Number value encountered.
> In integralCalc/iterateScalarValued (line 349)
In integralCalc/vadapt (line 132)
In integralCalc (line 91)
In integral (line 88)
In Percentile3FnNSH>@(Pk)integral(f,-inf,Pk)-k
In fzero (line 238)
In Percentile3FnNSH (line 30)
Error using fzero (line 240)
Function values at interval endpoints must be finite and real.
Error in Percentile3FnNSH (line 30)
solPk = fzero(@(Pk) integral(f,-inf,Pk)-k,[-10,10])
Mikie
2018년 5월 1일
Also, there is another problem when
a = 2.5
b = 0.2
c = 2
d = 0.1
I am wondering why it didn't work for some combination of a,b,c, and d. Thank you so much.
Walter Roberson
2018년 5월 1일
Don't do that. Split the integral at 0 like I advised.
syms u x pk
a = 30;
b = 0.2;
c = 20;
d = 0.1;
k = 0.01;
m = 1./(2.^(a+c-1).*gamma(a).*gamma(c).*b.^a.*d.^c);
h(u,x) = m.*(u+x).^(a-1).*(u-x).^(c-1).*exp(-(u+x)./(2.*b)-(u-x)./(2.*d));
syms xm negative
syms xp positive
fm = int(h(u,xm),u,-xm, inf);
intm = int(fm, xm, -inf, xm);
int0 = subs(intm, xm, 0);
if int0 > k
disp('pk is negative, resolving it');
solpk = vpasolve(intm - k);
solpkn = fzero( matlabFunction(intm-k), [-10 0]);
else
disp('pk is positive, resolving it');
fp = int(h(u,xp),u,xp,inf);
intp = int(fp, xp, 0, xp);
solpk = vpasolve(intp + int0 == k);
solpkn = fzero( matlabFunction(intp + int0 - k), [0 10]);
end
display(solpk)
display(solpkn)
Mikie
2018년 5월 1일
Oh Thank you so much. This is help me a lot. I still have another problem dealing with the integral. Could you please help me?
syms u x pk
k = 0.99
a = 5
b = 0.2
c = 40
d = 0.1
D1 = ((a.*b.^2+c.*d.^2).^3)/((a.*b.^3-c.*d.^3).^2);
D = (1/(2.*pi)).*((4./pi)-1)^2.*D1;
syms t
fun = (D+(2./pi).^3).*t.^3 - (3.*(2./pi).^2).*t.^2 + 3.*(2./pi).*t - 1;
theta = double(vpasolve(fun,t,[-Inf Inf]));
lambda = sign(a.*b.^3 - c.*d.^3).*sqrt(theta./(1-theta)); %sign
sigma = sqrt((a.*b.^2+c.*d.^2)./(1-(2./pi).*theta));
mu = a.*b-c.*d-sigma.*sign(a.*b.^3 - c.*d.^3).*sqrt(2./pi.*theta);
p = matlabFunction(2./sigma.*normpdf((x-mu)./sigma).*normcdf(lambda.*(x-mu)./sigma));
solPkS = fzero(@(PkS) integral(p,-Inf,PkS)-k,[-10,10]);
Here, I cannot solve for solPkS. It said that
Error using fzero (line 246)
FZERO cannot continue because user-supplied function_handle ==> @(PkS)integral(p,-Inf,PkS)-k failed with the error below.
Too many input arguments.
Error in Percentile3FnNSH (line 56)
solPkS = fzero(@(PkS) integral(p,-Inf,PkS)-k,[-10,10]);
Your help is greatly appreciated.
Walter Roberson
2018년 5월 2일
The denominator of D1 = ((a.*b.^2+c.*d.^2).^3)/((a.*b.^3-c.*d.^3).^2); is 0, so D1 is inf, leading to empty theta, leading to matlabFunction being applied to a constant empty array. When you matlabFunction something that is a constant and you do not specify the 'vars' then it generates a function handle with no arguments.
Mikie
2018년 5월 3일
Thank you so much. I still have another problems. Is it possible for these cases:
a=40; b=0.1;c=60;d=0.0667;
and
a=30;b=0.1;c=75;d=0.0667;
How can I fix this? Thank you.
Mikie
2018년 5월 3일
편집: Mikie
2018년 5월 3일
a=40;b=0.1;c=60;d=0.0667;k=0.99;
m = 1./(2.^(a+c-1).*gamma(a).*gamma(c).*b.^a.*d.^c);
h(u,x) = m.*(u+x).^(a-1).*(u-x).^(c-1).*exp(-(u+x)./(2.*b)-(u-x)./(2.*d));
syms xm negative
syms xp positive
fm = int(h(u,xm),u,-xm, inf);
intm = int(fm, xm, -inf, xm);
int0 = subs(intm, xm, 0);
if int0 > k
disp('pk is negative, resolving it');
solpk = vpasolve(intm - k);
solpkn = fzero(matlabFunction(intm-k), [-10 0]);
else
disp('pk is positive, resolving it');
fp = int(h(u,xp),u,xp,inf);
intp = int(fp, xp, 0, xp);
solpk = vpasolve(intp + int0 == k);
solpkn = fzero(matlabFunction(intp + int0 - k), [0 10]);
end
D1 = ((a.*b.^2+c.*d.^2).^3)/((a.*b.^3-c.*d.^3).^2);
D = (1/(2.*pi)).*((4./pi)-1)^2.*D1;
syms t
fun = (D+(2./pi).^3).*t.^3 - (3.*(2./pi).^2).*t.^2 + 3.*(2./pi).*t - 1;
theta = double(vpasolve(fun,t,[-Inf Inf]));
lambda = sign(a.*b.^3 - c.*d.^3).*sqrt(theta./(1-theta)); %sign
sigma = sqrt((a.*b.^2+c.*d.^2)./(1-(2./pi).*theta));
mu = a.*b-c.*d-sigma.*sign(a.*b.^3 - c.*d.^3).*sqrt(2./pi.*theta);
p = matlabFunction(2./sigma.*normpdf((x-mu)./sigma).*normcdf(lambda.*(x-mu)./sigma));
solPkS = fzero(@(PkS) integral(p,-Inf,PkS)-k,[-10,10]);
display(solpk)
display(solpkn)
display(solPkS)
Walter Roberson
2018년 5월 3일
The integral fm involves pretty much every combination of u and x with total power not exceeding (a+c-1), so in this case 40+60-1 = 99. That is 99*98/2 terms for that portion. It takes MATLAB a while to compute... and then it has to do the integral over that for fm. Takes a while :(
Mikie
2018년 5월 3일
But the process is stopped:
Error using symengine
Out of memory.
Error in sym/int (line 162)
rSym = mupadmex('symobj::intdef',f.s,x.s,a.s,b.s,options);
Error in FnNSH (line 29)
intm = int(fm, xm, -inf, xm);
How can I fix it?
Walter Roberson
2018년 5월 3일
Ah, that does not surprise me, Now that you have mentioned it, I see that MuPAD silently died underneath me; I have 32 gigabytes of RAM but it must have filled it up and croaked.
You are probably going to need to switch to a more numeric path.
Walter Roberson
2018년 5월 3일
Bleh. The int() that it creates for fm involves a limit() as u approaches infinity, which is an operation that effectively cannot be converted using matlabFunction :(
Walter Roberson
2018년 5월 4일
You might be interested to know that c = 56 does not produce the limit() inside fm, but that c = 57 does.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Special Values에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)