Sieve of Eratosthenes Here’s the fortran implementation of Sieve of Eratosthenes, an ancient method for finding prime upto n numbers (and one of the efficient method for finding small primes).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 program sieve_of_eratosthenes use, intrinsic :: iso_fortran_env, only : error_unit implicit none call prime_sieve_eratosthenes(170) contains subroutine prime_sieve_eratosthenes(n) integer, intent(in) :: n logical :: is_prime(2:n) !Today, I’ve forked All Algorithms archive for Fortran and have implemented few algorithms. Today’s highlight has been gauss elimination method!Gauss Elimination is a well known method for solving system of linear equations. It has time complexity of order $O(n^3)$ and hence, it fares better than cramer’s rule or Gauss-Jordan method.
The following is my implementation of Gauss elimination method in fortran. I’ve made use of scaled pivoting in order to reduce round-off errors.It’s been a great experience today, solving the tower of hanoi. Though a simple solution, the implementation was hard especially since I made some mistake in variable which took more than an hour (and resorting to gdb) to debug. So, the victory feels sweet.Today’s venture was rather short. I reimplemented the logistic map with elemental function. Here’s the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 program logisticmap use, intrinsic :: iso_fortran_env, only : dp=>real64, error_unit implicit integer(i-k) integer, parameter :: l=2001, b = 2001 real(dp) :: r(l), x0(b), x(l, b) integer :: fileno, istat, n character(len=1024) :: msg print *, "No of iterations: " read *, n x0 = linspace(0.