Questions regarding straight lines, slope, intercept, roots in MATLAB

139 Views Asked by At

In MATLAB the two following points with $x$ coordinates and $y$ coordinates are given

x = [7,11];
y = [0,0.29];

The following quantities are evaluated in MATLAB

a(1) = (y(1)-y(2))./(x(1)-x(2))

b(1) = (y(2).*x(1)-y(1).*x(2))./(x(1)-x(2))
c(1) = (b(1).^2 - (b(1)+x(1).*a(1)).^2)./(2.*a(1))

I understand the first one is the slope of the line. I assume the second in the intercept? Can anyone confirm my understanding? What is c(1) code line doing?

Moreover, the quantities below were also evaluated

umax = ((a(1).*x(2)+b(1)).^2-(b(1).^2-2.*a(1).*c(1)))./(2.*a(1))
u = rand(1,1);
index = find((u >= 0) & (u < umax));
g(index) = (-b(1) + sqrt(b(1).^2 - 2.*a(1).*(c(1)-u(index))))./a(1); 

Any ideas what these lines of codes are doing ? I understand the last one is similar to solving the root of 2nd order polynomial equation, but I don't understand what the steps are doing with respect to $u the random number.

Thanks.