Respuesta aceptada

Birdman
Birdman el 7 de Feb. de 2018
Editada: Birdman el 7 de Feb. de 2018

1 voto

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 comentarios

Raiven Balderas
Raiven Balderas el 7 de Feb. de 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 el 7 de Feb. de 2018
Use this:
plot((1:numel(primes(n)))+1,primes(n),'-o')
Birdman
Birdman el 7 de Feb. de 2018
It does plot. For instance:
n=10;
plot((1:numel(primes(n)))+1,primes(n),'-o')
and check the attached figure.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 7 de Feb. de 2018

Comentada:

el 7 de Feb. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by