MATLAB Answers

Try to answer bonus question

2 views (last 30 days)
Raiven Balderas
Raiven Balderas on 7 Feb 2018
Commented: Birdman on 7 Feb 2018
Screenshot is attached. Comment what the code to the bonus question is. Also provide explanations.

  0 Comments

Sign in to comment.

Accepted Answer

Birdman
Birdman on 7 Feb 2018
Edited: Birdman on 7 Feb 2018
By using primes built in function of MATLAB:
function y=prime_count(n)
y=numel(primes(n));
plot(primes(n))
end
From command line:
prime_count(10)
>> 4

  3 Comments

Raiven Balderas
Raiven Balderas on 7 Feb 2018
what happened to the k? it doesn't go in the code? the question says to plot pi(k) vs k for k=2,3,4..10^6
?
Birdman
Birdman on 7 Feb 2018
Use this:
plot((1:numel(primes(n)))+1,primes(n),'-o')
Birdman
Birdman on 7 Feb 2018
It does plot. For instance:
n=10;
plot((1:numel(primes(n)))+1,primes(n),'-o')
and check the attached figure.

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags