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 view (last 30 days)
Find the shortest distance between the plane 3*x1+4*x2+x3=1 and the point (-1,1,1)

Answers (2)

Bruno Luong
Bruno Luong on 16 Dec 2018
Edited: Bruno Luong on 16 Dec 2018
n = [3;4;1];
d = abs((n'*[-1;1;1]-1)/sqrt(n'*n))
gives:
d =
0.1961
  2 Comments
Busra Tabak
Busra Tabak on 16 Dec 2018
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

Sign in to comment.


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

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!