# How i can write a standard code for a report?

3 views (last 30 days)
jakaria babar on 7 Feb 2020
Edited: jakaria babar on 7 Feb 2020
Here is my code.
%% This program return the coordinates of a point P is connected to three fixed points A(6,9),B(20,38),C(49,25) such that the total length of the connector system is minimum and return the minimum total length and also the inputed values x and
clc
clear
x = input('enter the value of x:');
% The first input value within the domain of x is assigned to 'x'
y = input('enter the value of y:');
% The second input value within the domain of y is assigned to 'y'
xint = x;
% the input x is assigned to the initial value of x
yint = y;
% the input y is assigned to the initial value of y
dL_dx = (x-6)/sqrt((x-6)^2+(y-9)^2)+(x-20)/sqrt((x-20)^2+(y-38)^2)+(x-49)/sqrt((x-49)^2+(y-25)^2);
%dL_dx is the first derivative of L with respect to x
dL_dy = (y-9)/sqrt((x-6)^2+(y-9)^2)+(y-38)/sqrt((x-20)^2+(y-38)^2)+(y-25)/sqrt((x-49)^2+(y-25)^2);
%dL_dy is the first derivative of L with respect to y
% The vector u is defined as u=(dL_dx, dL_dy);the length of the vector u is
% sqrt((dL-dx)^2+(dL_dy)^2)
while sqrt((dL_dx)^2+(dL_dy)^2)>.001
%if the length of the vector u is greater than .001 , update the value
%of 'x' and 'y'. if not, stop.
x=x-.01*dL_dx;
y=y-.01*dL_dy;
dL_dx =(x-6)/sqrt((x-6)^2+(y-9)^2)+(x-20)/sqrt((x-20)^2+(y-38)^2)+(x-49)/sqrt((x-49)^2+(y-25)^2);
dL_dy =(y-9)/sqrt((x-6)^2+(y-9)^2)+(y-38)/sqrt((x-20)^2+(y-38)^2)+(y-25)/sqrt((x-49)^2+(y-25)^2);
L=sqrt((x-6)^2+(y-9)^2)+sqrt((x-20)^2+(y-38)^2)+sqrt((x-49)^2+(y-25)^2);
% L is the total length of the connector system.
end;
[xint yint]
% output initial value of 'x' and 'y'
[x y]
% output final value of 'x' and 'y'
L
% output total minimum length