Question: In MATLAB please!! Write a function ( not a script ) that does the following: ( a ) The input to the function is a

In MATLAB please!!
Write a function (not a script) that does the following:
(a) The input to the function is a positive integer n .
(b) The function will determine if the the number is a prime number or not.
(c) The function returns "1" if the number is prime and "0" if the number is not prime.
(d) The function should be called isPrimeNum() and exist in a file called isPrimeNum.m. Matlab/Oc-
tave are case sensitive.
(e) Matlab/Ocatve have a built-in function called isprime (n) that does this already. You can't call
that function in your function because that's cheating. You may use the built-in gcd function
though. Your function should start out this way.
function y = isPrimeNum(n)
% This function will compute if a positive integer n is prime.
if n 0
disp('Oops. n should be a positive integer');
y=-1;
return
end
if n ~= floor(n)
disp('Oops. n should be a positive integer');
y=-1;
return
end
%Your actual code should start below here.
Show results for running the following code
isPrimeNum(-6)
isPrimeNum(3.21)
isPrimeNum(7)
isPrimeNum(10)
isPrimeNum(77)
isPrimeNum(89)
In MATLAB please!! Write a function ( not a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!