Using Matlab: Function Name: twinPrimes Inputs: 1. (double) A vector of random i
ID: 667984 • Letter: U
Question
Using Matlab:
Function Name: twinPrimes Inputs:
1. (double) A vector of random integers
Outputs:
1. (logical) A vector describing whether each number of the original input vector is a
member of a pair of twin primes
Function Description:
Twin primes are a phenomenon in mathematics where a pair of prime numbers exist and
differ by only two. For example, 17 and 19 are both twin primes because they are prime numbers and the difference between them is 2. Another example of twin primes are the numbers 41 and 43. It is conjectured that an infinite number of twin primes exist, and proving this remains one of the most elusive problems in number theory to this day (Wolfram MathWorld).
Given an input vector of random integers, write a function in MATLAB that will determine which of the numbers in the input vector are members of a pair of twin primes.
Notes:
You must determine if the numbers in the vector are members of a pair of twin primes,
but each one could be the first in the pair or the second in the pair.
Each number in the vector will be of the value three or greater. This should not affect your code: it is to account for any corner cases (that could have potentially messed you
up) involving negative numbers and the isprime() function.
Hints:
The isprime() function may come in very handy for this function.
Explanation / Answer
Hi there,
Step 1:
Your requirements
{3,5}, {5,7}, {11, 13}, and {17, 19} are all twin prime pairs.
I just post here some code this will work very nice.
Step 3: output of this program prime pair : {5,7},...
Thanks for asking this query.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.