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

****** USE MATLAB ******** Sexy primes are two prime numbers that the difference

ID: 2293775 • Letter: #

Question

****** USE MATLAB ********

Sexy primes are two prime numbers that the difference between them is 6. For example, 23 and 29 are sexy primes since 29-23-6. Use loops to find all the sexy primes between 1 and 400. Store all sexy primes in a 2-column matrix where the 2 columns correspond to the 2 numbers in each pair of primes. (ie: 23 gets stored in column 1 and 29 gets stored in column 2.) Display the completed matrix. You may not use the built- in function "isprime" 2. The following is a list of 20 exam scores: 69, 81, 47,71, 54, 76, 60, 92, 85, 43, 88, 80, 79, 69, 26, 82, 89, 99, 71, 59. 3. Calculate the average of the top 8 scores, and display this average in the command window to 1 decimal place. 4. The elements of the symmetric Pascal matrix are obtained from: 1J Where iis the row number and j is the column number of the element. Use nested loops to create an 9x9 symmetric Pascal matrix. Display the completed matrix in the command window

Explanation / Answer

%answer (2)

%type the following command in matlab

clc

clear all
prime_list=[]
for k=1:1:400
L=mod(k,[1:400]);
L2=find(L==0);
if length(L2)<3
prime_list=[prime_list k];
end
end
prime_list
n=length(prime_list)
for h=1:1:n
nn=prime_list(h);
nnn=prime_list(h+1);
if nnn-nn==6
ll(h,:)=[nn nnn];
ll( ~any(ll,2), : ) = []

end
end

%REsult


ll =

23 29
31 37
47 53
53 59
61 67
73 79
83 89
131 137
151 157
157 163
167 173
173 179
233 239
251 257
257 263
263 269
271 277
331 337
353 359
367 373
373 379
383 389