MATLAB Answers

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 日間)
Busra Tabak
Busra Tabak 2018 年 12 月 16 日
回答済み: Alan Weiss 2018 年 12 月 17 日
Find the shortest distance between the plane 3*x1+4*x2+x3=1 and the point (-1,1,1)

  0 件のコメント

Sign in to comment.

回答 (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
Bruno Luong
Bruno Luong 2018 年 12 月 16 日
You are free to prefer 23 lines of code instead of 2.

Sign in to comment.


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

  0 件のコメント

Sign in to comment.

タグ


Translated by