In this lab, we will use MATLAB to implement primality tests, namely Fermat’s li
ID: 3109451 • Letter: I
Question
In this lab, we will use MATLAB to implement primality tests, namely Fermat’s little theorem and Wilson’s Theorem. We will also implement Fermat’s Last Theorem.
Please use basic MATLAB functions and processes to implement the following problems. Please read instructions carefull and include well detailed comments so that I can follow all steps and understand the code. Thanks in advance.
1. Wilson's Theorem (25 points) (p -1)! 1 Wilson's theorem states that a number p is prime if and only if the remainder of is 0 Implement Wilson's Theorem to determine whether a number is prime or not. Hint: In MATLAB when you receive your input variable, p, use the following statement p wint65 p) to convert p from a double to an unsigned integer that ranges from 0 to 18, f6,795,073,709, 551,61 2. Fermat's Little Theorem (25 points Fermat's little theorem states that a number p is prime if for all numbers a such that 1 S a p, p-1 the remainder of is 0. Implement Fermat's Little Theorem. Hint: As done in Problem 1 3. Speed Test (25 points) Use MATLAB's tic and toc function to determine the speed of determining whether a number p is prime or not using MATLAB's built-in isprime, MATLAB's built-in factor function, Wilson's Theorem, and Fermat's Little Theorem. Display the times of each function 4. Fermat's Last Theorem (25 points) "Fermat's Last Theorem states that no three positive integers a,b, and c can satisfy the equation a" b c" for any integer value of n greater than two (From Wikipedia)." For n 2, we have the Pythagorean triples such as 13, 4, 5 where 3 42 52. In MATLAB, empirically verify Fermat's Last Theorem for bounded values of a, b, and c as seen below 1 5 2 6 3 5 where a is the set of integers from 1 to 5, b is the set of integers from 2 to 6, and c is the set of integers from 3 to 5. To receive input from the user as a matrix, use the code below: data str2num (input Enter the bounds for a, b, and c 's')); Enter the bounds for a, b, and c: 1 5; 2 6; 3 5 will save the matrix seen above in data. Also, take as input from the user the value of n. If the user inputs 2 for n, a sample output is given below: a b be a c c Equal? 3 9 False 39 4 16 25 5 25 True 5 25 6 36 61 5 25 FalseExplanation / Answer
SOLUTION 1
MATLAB CODE FOR WILSON'S THEOREM
prompt = 'Enter the value of P';
p = input(prompt); %taking the input
p = uint64(p); %convert p to double to unsigned integer
if(mod((factorial(p-1)+1),p)==0) %checking the condition for p whether it is prime or not
disp('p is prime')
else
disp('p is not a prime')
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.