I don't understand the condition from FOR row 16 to row 26

1 回表示 (過去 30 日間)
Ngo Ha Gia Bao
Ngo Ha Gia Bao 2022 年 5 月 19 日
編集済み: David Hill 2022 年 5 月 19 日
syms x y z lambda
dist = x.^2+(y-1).^2+z.^2; % distance of an abitary point (x,y,z) from the point(0,1,0)
S = z.^2-(x.*y)-1 == 0; % surface constraint z^2 = xy+1 ------> z^2-xy-1 == 0
L = dist + lambda * lhs(S); % Langrange function
dL_dx = diff(L,x) == 0; % derivative of L with respect to x
dL_dy = diff(L,y) == 0; % derivative of L with respect to y
dL_dz = diff(L,z) == 0; % derivative of L with respect to z
dL_dlambda = diff(L,lambda) == 0; % derivative of L with respect to lambda
system = [dL_dx; dL_dy; dL_dz; dL_dlambda]; % build the system of equations
[x_val, y_val, z_val,lambda_val] = solve(system, [x y z lambda], 'Real', true); % solve the system of equations and display the results
results_numeric = double([x_val, y_val, z_val]); % show results in a vector of data type double
[rows columns]=size(results_numeric); % getting number of rows and columns
fprintf('points on the surface S that are closest to the point (0, 1, 0) are :\n');
fprintf(' x y z\n');
fprintf('--------------------------\n');
for i=1:rows
fprintf('(');
for j=1:columns
if j < columns
fprintf("%.4f , ",results_numeric(i,j));
else
fprintf("%.4f",results_numeric(i,j));
end
end
fprintf(")\n");
end

回答 (1 件)

David Hill
David Hill 2022 年 5 月 19 日
編集済み: David Hill 2022 年 5 月 19 日
The whole nested for-loop is just used to display results_numeric. If you don't care about displaying, you can delete the whole thing.
results_numeric%contains all the information within the matrix

カテゴリ

Help Center および File ExchangeNaNs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by