# 检查点是否在多维度椭圆体内

function [] = Checkup()
points  = [[ 0.53135758, -0.25818091, -0.32382715]
[ 0.58368177, -0.3286576,  -0.23854156,]
[ 0.18741533,  0.03066228, -0.94294771]
[ 0.65685862, -0.09220681, -0.60347573]
[ 0.63137604, -0.22978685, -0.27479238]
[ 0.59683195, -0.15111101, -0.40536606]
[ 0.68646128,  0.0046802,  -0.68407367]
[ 0.62311759,  0.0101013,  -0.75863324]];
P = points\'; % <- remove the \ symbol here
dimen = length(P(:,1));

% c - vector with ellipse centers
[A, c] = MinVolEllipse(P, 0.01);
[~, Q, V] = svd(A);

for i = 1:dimen
radiuses(1, i) = 1 / sqrt(Q(i,i));
end

% Check if points lie within ellipse and print Ok for every point inside ellipsoid
for i = 1:length(P(1,:)) % length(P(1,:)) is number of points
value = 0;
for j = 1:dimen
%adding ((p_i - c_i) / (r_i))^2 value
value = value + ( ( (P(j,i) - c(j, 1) )^2 ) / (radiuses(1, j)^2));

end
if value <= 1
disp('Ok')
end
end

## 我的方法

1. 更新位置，如下所示：point = point-center->换句话说，将其转换为椭圆体使其居中于点（0，0，... 0）

2. 像椭圆体平行于所有轴一样旋转：point = invert（V）* point

4. 如果方程式给出结果<= 1，则点位于椭圆内。

## 正确的解决方案

function [result] = Ellipse()
% Returns vector consisting of 10 entries
% that represent error ratio for every test set

result = 0:9;

% Run tests for all point sets
for pointSet = 0:9
count = 0;

% c - vector with ellipse centers
[A, c] = MinVolEllipse(Ptraining, 0.00001);

% Check if points lie within ellipse
for i = 1:length(Ptest(1,:)) % length(P(1,:)) is number of points
pp = Ptest(:, i) - c;
value = pp' * A * pp;
if value > 1
count = count + 1;
end
end

% Get the error ratio
index = pointSet + 1;
result(index) = count / length(Ptest(1,:));
end

end

tol_mvee = 0.01;
tol_dist = 0.1;

[A, c] = MinVolEllipse(P, tol_mvee);

% Check if points lie within ellipse and print Ok for every point inside ellipsoid
for i = 1:length(P(1,:)) % length(P(1,:)) is number of points
x   = P(i,:);
x_c = x-c;
d   = dot(x_c, A*x_c);
if d < 1+tol_dist
disp('Ok');
end
end

0 条评论