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 visualización (últimos 30 días)
Find the shortest distance between the plane 3*x1+4*x2+x3=1 and the point (-1,1,1)

Respuestas (2)

Bruno Luong
Bruno Luong el 16 de Dic. de 2018
Editada: Bruno Luong el 16 de Dic. de 2018
n = [3;4;1];
d = abs((n'*[-1;1;1]-1)/sqrt(n'*n))
gives:
d =
0.1961
  2 comentarios
Busra Tabak
Busra Tabak el 16 de Dic. de 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

Iniciar sesión para comentar.


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

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by