Can anyone solve this? Find the shortest distance between the plane 3*x1+4*x2+x3=1 and the point (-1,1,1). (optimization problem?)

1 次查看(过去 30 天)
Find the shortest distance between the plane 3*x1+4*x2+x3=1 and the point (-1,1,1)

回答(2 个)

Bruno Luong
Bruno Luong 2018-12-16
编辑:Bruno Luong 2018-12-16
n = [3;4;1];
d = abs((n'*[-1;1;1]-1)/sqrt(n'*n))
gives:
d =
0.1961
  2 个评论
Busra Tabak
Busra Tabak 2018-12-16
thank you, correct answer but this is not optimization solution. I tried this code
syms x1 x2 x3 r ll
f=3*(x1+1)+4*(x2-1)+(x3-1);
g=3*x1+4*x2+x3-1;
L=f-r*g;
gradL=gradient(L);
[x1s x2s x3s rs]=solve(gradL==0,[x1 x2 x3 r],'Real',true);
h=.01;
k=.01;
for i=1:numel(x1s)
fopt=double(subs(f,[x1 x2 x3],[x1s(i) x2s(i) x3s(i)]));
gc=subs(g,[x1 x2 x3],[x1s(i)+h x2s(i)+k x3s(i)+ll]);
l=double(solve(gc==0,ll));
[a j]=min(abs(l));
l=l(j);
fnear=double(subs(f,[x1 x2 x3],[x1s(i)+h x2s(i)+k x3s(i)+l]));
[x1s(i) x2s(i) x3s(i)]
fopt=sqrt(fopt)
if fopt<fnear
disp('min')
elseif fopt>fnear
disp('max')
end
end

请先登录,再进行评论。


Alan Weiss
Alan Weiss 2018-12-17
If you want to use an optimization technique, see Shortest Distance to a Plane.
Alan Weiss
MATLAB mathematical toolbox documentation

类别

Help CenterFile Exchange 中查找有关 Discrete Math 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by