Skip to content
Snippets Groups Projects
Commit 83a0cdc6 authored by Lauren Yulitza Parra Duque's avatar Lauren Yulitza Parra Duque
Browse files

Upload New File

parent 1fbe8e17
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id:cb02fe2a-61f8-46cb-acdc-dc210bb9f9df tags:
``` python
import numpy as np
import matplotlib.pyplot as plt
```
%% Cell type:code id:9d609fc9-be99-4e8d-87c7-cdcfbce35cc9 tags:
``` python
N = 150
num = np.arange(2, N+1)
num_prim = [num[0]]
for i in np.arange(1, len(num)):
for j in np.arange(0, i):
cond = num[i]%num[j]
if cond == 0:
#print(num [i], 'no es primo')
break
if cond != 0:
#print(num[i], 'es primo')
num_prim.append(num[i])
```
%% Cell type:code id:c387f96b-1f56-4744-b127-042342c10cda tags:
``` python
len(num_prim)
```
%% Output
35
%% Cell type:code id:899b39a7-9db3-44ac-8bd6-a9f26b5ae9cb tags:
``` python
def num_prim_func(N):
'''Retorna los numeros primos hasta N'''
num = np.arange(2, N+1)
num_prim = [num[0]]
for i in np.arange(1, len(num)):
for j in np.arange(0, i):
cond = num[i]%num[j]
if cond == 0:
#print(num [i], 'no es primo')
break
if cond != 0:
#print(num[i], 'es primo')
num_prim.append(num[i])
return num_prim
def counting_primes(N):
'''Retorna los numeros primos hasta N'''
num_prim = num_prim_func(N)
return len(num_prim)
```
%% Cell type:code id:686502f4-306b-4bbd-a606-319b94d0158e tags:
``` python
nums = np.arange(2, 1001)
y = []
for i in np.arange(0, len(nums)):
y.append(counting_primes(nums[i]))
y = np.array(y)
```
%% Cell type:code id:7e687425-7393-494d-8c84-17959ee7bc2f tags:
``` python
plt.figure()
plt.plot(nums, y, '.')
plt.plot(nums, np.rint(nums/np.log(nums)))
plt.show()
```
%% Output
%% Cell type:code id:6655c7c4-31f8-44ec-8824-db658406e97e tags:
``` python
f = np.rint(nums/np.log(nums))
error_p = np.abs(y-f)/y*100
```
%% Cell type:code id:d0f62e9c-c2b8-4f53-9110-f27b2d550fd2 tags:
``` python
plt.figure()
plt.plot(nums[10:], error_p[10:])
```
%% Output
[<matplotlib.lines.Line2D at 0x22422fe3400>]
%% Cell type:code id:671005a5-8863-47c5-a470-e70be623c1e1 tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment