Write a MATLAB m-file calculating the leading Pythagorean triplets.
Answers
Answered by
1
Answer:
If your intent is to use a nested loop, then your loops can be made more efficient.
1. Since all triples have side lengths at least 3, start with 3, not 1.
2. No triples ever have two sides that are the same length.
3. For uniqueness, we can require that a<b<c
4. If X is the sum of the side lengths, then the smallest side length could never be larger than X/3.
5. Since you KNOW the sum, there is NO need to use a triple loop at all. A double loop will suffice.
therefore the limits for your loops might be more intelligently chosen as:
for a = 3:(X/3)
for b = (a+1):((X - a)/2)
c = X - a - b;
if (a^2 + b^
Please mark as brainliest
Similar questions