, , . , .
Matlab, Matlab R2015b JIT -Compiler, , , .
[n,~] = size(C);
%// division
d = bsxfun(@rdivide,C,C(:,1));
%// create blocks for eigen matrix block procession
X = ( [zeros(n,1) ones(n,1) -d(:,3) -d(:,2)] ).'; %'
Y = reshape(X,2,[]);
%// use block processing to get eigenvalues of blocks
rt = blockproc(Y,[2 2],@(x) eig(x.data) ).'; %'
%// check if eigen values are real positives
condition = rt == abs(rt);
%// output filter
out = rt(condition);
Benchmark
function [t] = bench()
%// load your data
DATA = load('matlab');
C = DATA.QuadraticCoefficients;
% functions to compare
fcns = {
@() thewaywewalk(C);
@() sepideh(C);
};
% timeit
t = zeros(2,1);
for ii = 1:10;
t = t + cellfun(@timeit, fcns);
end
end
function out = thewaywewalk(C) %thewaywewalk
[n,~] = size(C);
d = bsxfun(@rdivide,C,C(:,1));
X = ( [zeros(n,1) ones(n,1) -d(:,3) -d(:,2)] ).'; %'
Y = reshape(X,2,[]);
rt = blockproc(Y,[2 2],@(x) eig(x.data) ).'; %'
condition = rt == abs(rt);
out = rt(condition);
end
function out = sepideh(C) %sepideh
[n,~] = size(C);
out = zeros(n,1);
for ii = 1:n
c = C(ii,:);
d = c./c(1);
rt = eig([0 -d(3);1 -d(2)]);
condition = rt == abs(rt);
rt = rt(condition);
if isempty(rt)
rt = 0;
end
rt = max(rt);
out(ii) = rt;
end
end
ans =
12.2086 %
9.2176 %
if-.