Integral of matrix determinant
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Zhenghao Yang
am 6 Mär. 2023
Kommentiert: Zhenghao Yang
am 7 Mär. 2023
I found that it seems the
integral
fucntion cannot integrate determinant. For example
f=@(x)det([1,x;0,2]);
integral(f,0,1)
does not return a proper result. Of course we can mannually take
f=@(x)(2*1-0*x);
but this can be hardly applied to larger matrices. Is there a solution to this problem?
0 Kommentare
Akzeptierte Antwort
Torsten
am 6 Mär. 2023
f=@(x)det([1,x;0,2]);
integral(f,0,1,'ArrayValued',true)
2 Kommentare
Torsten
am 6 Mär. 2023
Bearbeitet: Torsten
am 6 Mär. 2023
1d:
f = @(x) det([1,x;0,2]);
value = integral(@(X)arrayfun(@(x)f(x),X),0,1)
2d:
f = @(x,y)det([x 2*y^2;0 3*sin(x*y)]);
value = integral2(@(X,Y)arrayfun(@(x,y)f(x,y),X,Y),0,1,0,1)
3d:
f = @(x,y,z) det([x 2*y^2 z;0 3*cos(x*z) log(z+1);4*exp(y+z) cos(z) 1/(x+1)]);
value = integral3(@(X,Y,Z)arrayfun(@(x,y,z)f(x,y,z),X,Y,Z),0,1,0,1,0,1)
Weitere Antworten (2)
John D'Errico
am 6 Mär. 2023
For this specific problem, I might just suggest that the determinant of an upper triangular matrix is just the product of the diagonal elements.
syms x
A = [1 x;0 2]
As such, the use of det or integral is wild overkill here, since the determinant is independent of the value of x.
det(A)
Why does integral fail? Because it tries to pass in a list of points to evaluate the function at. And det is not vectorized. So this is not a problem of integral in reality, but of the interaction between integral and det. Integral insists on the function being vectorized. Det insists is it NOT vectorized. Failure!
The solution is to evaluate the determinant as a polynomial in symbolic form, and then integrate, or do as @Torsten has shown, to use the 'arrayvalued' option in integral.
help integral
And, to be honest, the help does not really state that this is how you can avoid the need for your objective function to be vectorized.
f=@(x) det([1 x;0 2]);
integral(f,0,1,'ArrayValued',true)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!