Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Matlab: Function Name: twinPrimes Inputs: 1. (double) A vector of random i

ID: 668111 • 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

% Finds all twin primes which are less than or equal to N N = input ('Enter Integer value to search primes up to:'); y = 0; % y is a function of N which is the actual value of number of twin primes less than N gR = 0; % gR is a function of N which is the estimated value of number of twin primes less than N C = 0.6601618158; % The twin prime constant to 10 dp func = @(x)1./(log(x).^2); % Is the function inside the integral in the calculation for gR (Extra information in hyperlink) for(i = 2:N) x = 0; if(isprime(i) + isprime (i+2) == 2) %Checks if a number i and the number two greater than it are both prime x = 1; end y(i) = y(i-1) + x; gR(i) = 2*C*integral(func,2,i); %calculate the estimated value of the number of twin primes less than N as a function of N end fprintf('The number of primes less than %u is: %u ',N , y(N)) plot(1:N,y) %Plots the number of twin primes as a function of N hold on plot(1:N,gR) %Plots the approximation of the curve alongside the above graph %Equations for estimated value of the number of twin primes less than N was found at: %https://cs.uwaterloo.ca/journals/JIS/VOL8/Dubner/dubner71.pdf

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote