This must be done in matlab A Pythagorean triplet is a set o
This must be done in matlab.
A Pythagorean triplet is a set of three natural numbers, a 0. Here is the formula: a = m^2 - n^2, b = mn c = m^2 + n^2 So, we can see that this problem can be alternatively thought of as trying to determine m and n for which a +b c 1000 and then multiplying abc to find the answer. There are many, many different ways of approaching this problem, and many of them are perfectly correct. However, to encourage you to think hard about the best solution, your final code must take less 1 minute to run. You can verify this via tic/toc. For this problem you should include the following in your code, as comments: The final answer, abc. The elapsed time that it takes for your code to run (as determined by you). This problem is worth 10 pointsSolution
Matlab code:
t = cputime;
sum = 1000;
for a = 1:sum/3
for b = a+1:sum/2
c = sum - a - b;
if(a*a + b*b == c*c)
a
b
c
fprintf(\'abc= %i\ \',a*b*c);
end
end
end
time = cputime-t
Output:
