a = input('Enter a: ');
if a ≤ 0, error('a must be positive'); end
c = input('Enter c: ');
if c ≤ 0, error('c must be positive'); end
if c < a, error('c must be greater than a'); end
fprintf('The value of b is %g\n', findb(a,c));
function b = findb(a,c)
b = sqrt(c^2 - a^2);
end
Mathematical Background:
This solution implements the Pythagorean theorem: a² + b² = c²
Rearranged to solve for b: b = √(c² - a²)
Constraints:
- a > 0 (positive length)
- c > 0 (positive length)
- c > a (hypotenuse must be longer than other sides)
- c² ≥ a² (to avoid imaginary numbers)