Opening the book…
This is a modified version of Allen B. Downey's section. It was modified by Carey Smith to use parentheses for clarity and to remove possible ambiguity.
The first step is to create a logical function, which is a function that returns a logical value. The following function takes three input variables, a, b, and c, and returns true (1) if they form a Pythagorean triple and false (0) otherwise.
function res = is_pythagorean(a, b, c)
if ( (a^2 + b^2) == c^2)
res = 1;
else
res = 0;
end
end
We can use this function like so:
>> is_pythagorean(3, 4, 5)
ans = 1
Put this function in a file called is_pythagorean.m, so we can use it as part of our program.
This page titled 6.5: Logical Functions was last modified on Fri, 17 Feb 2023 05:30:30 GMT and is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Carey Smith via source content that was edited to the style and standards of the LibreTexts platform.
The book could not be loaded just now.