Specifically, we are asked to create a function that will determine if a number is prime without using a for loop. In this circumstance your function should be vectorized. I have figured out how to determine if a number is prime with a for loop, but I am unsure how to determine if a number is prime by writing a function using a vector. Any help would be greatly appreciated.

This is what I have tried already, but I get no results for my output:

function [noloop]=isPrime_noloop(n)

n = ones(1,40000000);

j = 2;

while(j<(40000000/2))

n((j*2):j:end) = 0;

j = j+1;

while(n(j)==0) % find next prime

j = j+1; end

end

As I said, I am not sure if I am on the right path or not, this is all new to me. I appreciate any and all responses.

Cheers!