numerical integraion with array limits

11 ビュー (過去 30 日間)
Wenjuan
Wenjuan 2013 年 12 月 6 日
編集済み: Sergio Quesada 2018 年 6 月 1 日
I am trying to work out the integrals that are function of one of the limits, and both limits are vectors:
n=1:10;
t=2;
a=(n-1).*t;
b=n.*t;
Q=integral(@(x)lognpdf(b-x,2,1),a,b,'ArrayValued',true);
As a and b must be scalars, so integral won’t work here. Someone suggested using arrayfun in the answers to a similar question in April where only one limit is a vector, how to do this?

採用された回答

Mike Hosea
Mike Hosea 2013 年 12 月 6 日
編集済み: Mike Hosea 2013 年 12 月 6 日
Assuming you want each individual integral to be
integral(@(x)lognpdf(b(j)-x,2,1),a(j),b(j))
then
Qab = @(aj,bj)integral(@(x)lognpdf(bj-x,2,1),aj,bj)
Q = arrayfun(Qab,a,b)
You don't have to rename a and b in Qab, as they are "scoped" to be distinct from the previously defined a and b vectors, but I just did it for clarity.
  4 件のコメント
Wenjuan
Wenjuan 2013 年 12 月 6 日
編集済み: Wenjuan 2013 年 12 月 6 日
Now I am trying to work out double integral, where the limit of y is a function of x, like
fun=@(x,y)lognpdf(b-x,2,1).*lognpdf(y,3,2);
ymax=@(x) b-x;
Qab=@(a,b)integral2(fun,a,b,0,ymax);
Q=arrayfun(Qab,a,b);
but this returns error
"
Error using -
Matrix dimensions must agree.
Error in @(x)b-x"
Is this because b is a vector?
Mike Hosea
Mike Hosea 2014 年 1 月 22 日
Yes, but the problem is that the value for b is obtained as a snapshot when @(x)b-x is created. You should be able to work around this problem by inlining the creating of ymax, i.e.
ab=@(a,b)integral2(fun,a,b,0,@(x)b-x);

サインインしてコメントする。

その他の回答 (1 件)

Sergio Quesada
Sergio Quesada 2018 年 6 月 1 日
編集済み: Sergio Quesada 2018 年 6 月 1 日
Hi everybody, I'm working on a similar easier case, but with no success... I'm trying to evaluate
liminf=ones(1,20); syms x;
integral(@(x)exp(-a./x.*log(x)),liminf,r)
beeing 'a' an escalar, and 'r' also a 1x20 array. That is, 20 different integrals from 1 to each value of 'r'
It sais:
Error using integral (line 85)
A and B must be floating-point scalars.
Thankyou so much !!

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by