採用された回答

Birdman
Birdman 2018 年 2 月 7 日
編集済み: Birdman 2018 年 2 月 7 日

1 投票

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 件のコメント

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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Introduction to Installation and Licensing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by