Compare inv(X) Vs mex inv (X)
이전 댓글 표시
Hi all
I wrote a simple program which calculates inverse matrix size (100*100).
function y = test_inv(x) %#codegen
% test inverse matrix
y = inv(x);
end
I created mex function test_inv_mex and tested running time.
x = randn(100);
tic;
for n = 1: 100
y = test_inv(x);
end
toc;
tic;
for n = 1: 100
y = test_inv_mex(x);
end
toc;
This is my resulte :
Elapsed time is 0.054418 seconds.
Elapsed time is 0.613990 seconds.
My question is :
Why the mex function run much slower than regular one ?
B.R
Zohar
댓글 수: 4
Yash
2012년 7월 8일
dont use INV, try some other option instaed of INV because if you use it, in newer version it gives that its old and try something diff apart from that
check out help*
- Y = inv(X) returns the inverse of the square matrix X. A warning message is printed if X is badly scaled or nearly singular.
In practice, it is seldom necessary to form the explicit inverse of a matrix. A frequent misuse of inv arises when solving the system of linear equations . One way to solve this is with x = inv(A)*b. A better way, from both an execution time and numerical accuracy standpoint, is to use the matrix division operator x = A\b. This produces the solution using Gaussian elimination, without forming the inverse. See \ and / for further information.
Jan
2012년 7월 8일
@zohar: Please explain, how you have "created the mex function". It matters if you have a hand-coded function, call the optimized ATLAS or BLAS functions, or if you let the code generator do this, which is implied by the comment "%#codegen" appearing in your code. Good answers require no guessing of important details.
@Yash: Without doubt you a right. But zohar's question concerned another topic.
zohar
2012년 7월 8일
zohar
2012년 7월 8일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Execution Speed에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!