Matlab and Octave Programming for STEM Applications · LibreTexts
0%
Contents
Text
Size
From LibreTexts, under CC BY-NC-SA 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.
6.4: Incremental Development
Opening the book…
Now that we have relational operators and if statements, let’s start writing the program.
Here are the steps we will follow to develop the program incrementally:
Write a script named findtriples.m and start with a loop that enumerates values of a and displays them.
Write a second loop that enumerates values of b and a third loop that enumerates values of c.
Use the if statement from the previous section to check whether a, b, and c form a Pythagorean triple.
Display the values that pass the test.
Transform the script into a function and make it take an input variable that specifies the range to search.
Along the way, we’ll optimize the program to eliminate unnecessary work.