Question: CODE IN MATLAB! Part 1 The Pythagorean Theorem states that a2 + b2 = c2 . Write a MATLAB program that finds all the combinations
CODE IN MATLAB!
Part 1
The Pythagorean Theorem states that a2 + b2 = c2 . Write a MATLAB program that finds all the combinations of triples a, b, c that are positive integers all less than or equal to 30 that satisfy the Pythagorean Theorem. Display the results in a three-column matrix names PythagoreanTriples in which every row is one triple. Use three nested for loops and one if statement.
Part 2
Write a MATLAB program that finds all pairs of prime numbers between 1 and 100 whose difference is 6. Display the results in a two-column matrix named Diff6Primes in which every row is one pair. Use one for loop, one if statement, and the MATLAB function isprime.
Part 3
A perfect number is a positive integer that is equal to the sum of its positive divisors including 1 but not including the number itself. The first two perfect numbers are 6 and 28 since 6=1+2+3 and 28=1+2+4+7+14. Write a MATLAB program that finds the first three perfect numbers and displays them in a row vector named PerfectNumbers. Use two nested for loops where the loop variable of the outer for loop goes from 2 to 10000, three if statements, a break statement that breaks out of the outer for loop after the first three perfect numbers have been found, and the MATLAB function rem (rem(a,b) returns 0 if a is divisible by b).
Hint: If i is the loop variable of the outer for loop, the loop variable of the inner for loop will go from 1 to floor(i/2)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
