Q:

The Pythagorean theorem states that for a right triangle, the relationship between the length of the hypotenuse c and the lengths of the other sides a and b is given by:

0

The Pythagorean theorem states that for a right triangle, the relationship between the length of the hypotenuse c and the lengths of the other sides a and b is given by:

 c 2 = a2 + b2

Write a script that will prompt the user for the lengths a and c, call a function findb to calculate and return the length of b, and print the result. Note that any values of a or c that are less than or equal to zero would not make sense, so the script should print an error message if the user enters any invalid value. Here is the function findb:

findb.m

function b = findb(a,c)

% Calculates b from a and c

b = sqrt(c^2 - a^2);

end

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Ch4Ex7.m

c = input('Enter the length of c: ');

a = input('Enter the length of a: ');

if a > 0 && c > 0

 b = findb(a,c);

 fprintf('The length of b is %.1f\n', b)

else

 fprintf('Error in input\n')

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now