h = [-1 -2 0]j=sqrt(sum(h.^2));%Number conversion into string format
k=num2str(h(1));l=num2str(h(2));m=num2str(h(3));%Error message; distance input must be a positive real number
n=input('Enter the perpendicular distance from the origin: ');if n<=0 disp('The distance cannot be zero or negative. Try again.')else o=['The equation of the plane at a perpendicular distance' ... ' of ', num2str(n),' from the origin O, is ', k,'x + ', ... l,'y + ', m,'z = ', num2str(j*n),'.']; disp(o)end
When I input a distance of 2, the result is displayed as:
-1x + -2y + 0z = 4.4721.
Is there any way of displaying the output simply as:
-x - 2y = 4.4721.
where, the function automatically picks up the sign in the matrix and uses that instead of displaying both + and – . When the value is one it only displays the variable and when zero, it omits the variable from the output?
Thank you.
Best Answer