using integral2 on a matrix with function handler components

10 ビュー (過去 30 日間)
Navid
Navid 2014 年 4 月 25 日
編集済み: Star Strider 2014 年 4 月 25 日
Let's say that I have the following function: A = @(x,y) [x,x+y;x-y,y]; and I want to calculate the following integral: Q = integral2(A,0,2,3,5) How can I do this? How can I access and use the function that is defined inside the component i and j of my matrix? I cannot use e_i*A*e_j' because it is still matrix.
P.S. Here I know my function, but in my code I have a product of two different function handler matrix, thus I do not know my function s.t. I know here.

採用された回答

Star Strider
Star Strider 2014 年 4 月 25 日
編集済み: Star Strider 2014 年 4 月 25 日
It seems that integral2 doesn’t take matrix integrands, but integral will, with the 'ArrayValued',true option.
This looks slightly strange, but see if it does what you want it to:
A = @(x,y) [x, x+y; x-y, y];
Q = integral(@(y) integral(@(x)A(x,y) ,0,2, 'ArrayValued',true), 3,5, 'ArrayValued',true)
It does produce the correct results with the matrix in your example. (Hand-calculating them to check it is fairly straightforward, if slightly tedious.)
Q =
4.0000e+000 20.0000e+000
-12.0000e+000 16.0000e+000
  2 件のコメント
Navid
Navid 2014 年 4 月 25 日
Star Strider,
thank you for your answer. Unfortunately, in the double integral that I am using, the bound of the inner integral is function of the outer integral variable and this method takes so much time than the one that I explained\
Star Strider
Star Strider 2014 年 4 月 25 日
編集済み: Star Strider 2014 年 4 月 25 日
My pleasure!
I also experimented with separating the matrix into its components and using integral2 with each of them. That actually took much longer than the nested integral call with the 'ArrayValued',true option.
In the situation you describe, it will probably be necessary for you to loop over the double integral (or nested single integrals), integrating over a short sub-interval each time and substituting the value calculated by the outer integral in the inner integral at the end of each loop. It’s not ideal, but it’s probably the only way to approach that problem. The nested single integrals with the 'ArrayValued',true option will let you integrate your matrix, though.

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

その他の回答 (1 件)

Navid
Navid 2014 年 4 月 25 日
One way that I could find is to convert the function to symbolic then choose the appropriate component and then convert it back to function handler and find the integral. E.X. if I want to find the integral of component (1,2):
A = @(x,y) [x,x+y;x-y,y];
syms m n
p = A(m,n);
f = matlabFunction(p(1,2))
Q = integral2(f,0,2,3,5)
  1 件のコメント
Star Strider
Star Strider 2014 年 4 月 25 日
Nesting two calls to integral works, without having to break the matrix apart into its components.

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

カテゴリ

Help Center および File ExchangeNumbers and Precision についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by