×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Create A Histogram of Random Numbers Chosen with Normal Distribution Using Fortran 95 Assignment Solution

July 10, 2024
Dr. Samantha Chang
Dr. Samantha
🇨🇦 Canada
Programming
Dr. Chang is a seasoned software engineer with a Ph.D. in Computer Engineering from MIT. She has completed over 900 Programming assignments and specializes in optimizing code performance, debugging, and troubleshooting. Dr. Chang's expertise lies in ensuring efficient and scalable solutions for Groovy programming tasks.
Key Topics
  • Instructions
  • Requirements and Specifications
Tip of the day
Use well-structured shaders to optimize rendering and ensure efficient resource management. Start with simple shapes, gradually adding complexity, and debug in small steps to identify errors easily.
News
An open-source framework that allows developers to create rich Python applications in the browser using HTML's interface, bridging the gap between web development and Python scripting.

Instructions

Objective

Write a program to create a histogram of random numbers chosen with normal distribution using Fortran 95 assignment solution.

Requirements and Specifications

Create a histogram of random numbers chosen with normal distribution using Fortran 95

Screenshots of output

Create a histogram of random numbers chosen with normal distribution using Fortran 951

Source Code

PROGRAM Program1 IMPLICIT NONE REAL, PARAMETER :: PI=3.14159265358979323846 INTEGER, PARAMETER :: NGEN1 = 13000 REAL, PARAMETER :: AVG1 = 22.0 REAL, PARAMETER :: STDDEV1 = 2.5 INTEGER, PARAMETER :: NGEN2 = 7000 REAL, PARAMETER :: AVG2 = 15.5 REAL, PARAMETER :: STDDEV2 = 1.0 INTEGER :: i REAL :: n1, n2, ngauss INTEGER :: new_seed; ! Read seed print*, "Seed?" read*, new_seed ! set seed for random generator call srand(new_seed) open(11,FILE="Bumps.txt", STATUS='REPLACE', ACCESS='SEQUENTIAL',ACTION='WRITE') ! Generate 13000 numbers with gaussian distribution ! with average= 22.0 and stddev = 2.5 do i = 1, NGEN1 ! generate two numbers n1 = rand() n2 = rand() ! generate normally distributed number ngauss = boxMuller(n1, n2, AVG1, STDDEV1) write(11, *) ngauss end do ! Generate 7000 numbers with gaussian distribution ! with average= 15.5 and stddev = 1.0 do i = 1, NGEN2 ! generate two numbers n1 = rand() n2 = rand() ! generate normally distributed number ngauss = boxMuller(n1, n2, AVG2, STDDEV2) write(11, *) ngauss end do close(11) CONTAINS ! generate a random number with gaussian distribution ! and given average m and standard deviation s, using ! the Box-Muller algorithm based on the uniformly ! distributed numbers n1 and n2 REAL FUNCTION boxMuller(n1, n2, m, s) REAL, INTENT(IN) :: n1, n2, m, s REAL :: r, z1 r = sqrt(-2.0 * log(n1)) z1 = r*cos(2.0 * PI * n2) ! transform to given median and deviation boxMuller = m + s*z1 END FUNCTION boxMuller END PROGRAM Program1 PROGRAM Program2 IMPLICIT NONE INTEGER, PARAMETER :: NNUMBERS = 20000 REAL, PARAMETER :: HIST_MIN = 10 REAL, PARAMETER :: HIST_MAX = 30 INTEGER, PARAMETER :: HIST_NBOXES = 100 INTEGER :: i, box REAL :: n, boxwid, start INTEGER :: histogram(100) ! initialize histogram to zero do i = 1, HIST_NBOXES histogram(i) = 0 end do ! box size boxwid = (HIST_MAX - HIST_MIN) / HIST_NBOXES ! Read the 20000 numbers from the file and ! build histogram with the data open(11,FILE="Bumps.txt") do i = 1, NNUMBERS read(11, *) n if (n >= HIST_MIN .and. n <= HIST_MAX) then box = (n - HIST_MIN)/boxwid + 1 histogram(box) = histogram(box) + 1 end if end do close(11) ! write histogram to a file open(12,FILE="BumpsHist.txt", STATUS='REPLACE', ACCESS='SEQUENTIAL',ACTION='WRITE') do i = 1, HIST_NBOXES start = (i - 1)*boxwid + HIST_MIN write(12, *) start, histogram(i) end do close(12) END PROGRAM Program2 Contact Details

Related Samples

At ProgrammingHomeworkHelp.com, we provide comprehensive assignment support to students, including related samples of Fortran programming assignments. Our website is designed to help students excel in their programming courses by offering expertly crafted examples and detailed solutions. Whether you're struggling with Fortran code or need guidance on complex programming concepts, our resources are here to assist you. Explore our sample assignments to gain insights and improve your understanding, ensuring you achieve academic success in your programming studies.