Giter VIP home page Giter VIP logo

fortran-multiplicity-calculator's Introduction

Motivation

To explore the syntax of FORTRAN and learn a legacy language.

Original Problem

In Schroeder's Thermal Physics Problem 2.9, we were tasked by the author to recreate the same Figure 2.4 and then determine the most and least probable macrostate, along with their respective probabilities.

Problem 2.9

Problem 2.9

Figure 2.4

Figure 2.4

For our FORTRAN exercise, we aim to become familiar with FORTRAN syntax by solving the Total Multiplicity for six harmonic oscillators and four harmonic oscillators in each Einstein Solid, with a total of six energy units.

Original Solution

The original approach to solving this problem (back in October 2021) involved using Excel to generate the figures and address the remaining challenges.

Original Solution

Original Solution done in Excel

It was relatively simple to set up and generate figures without the need for pip install pandas or other Python packages. To tackle this problem using a more challenging approach, we considered doing it the FORTRAN way.

FORTRAN Solution

The FORTRAN approach (Checkout the .f90 file here!) successfully achieved the same Total Multiplicity as the original way (a total multiplicity of 5005) with the same input. Below is a pseudocode representation of the actual FORTRAN code.

    
Program MultiplicityCalculator
  Initialize n_A, n_B, q_A, q_B, q_Total, Omega_A, Omega_B, Multiplicity, TotalMultiplicity
  
  Input n_A, n_B, q_Total
  
  q_A = 0
  q_B = q_Total
  TotalMultiplicity = 0
  
  while q_A is not equal to q_Total + 1
    Calculate Omega_A using comb(q_A + n_A - 1, q_A)
    Calculate Omega_B using comb(q_B + n_B - 1, q_B)
    Calculate Multiplicity as Omega_A * Omega_B
    
    Print q_A, Omega_A, q_B, Omega_B, Multiplicity
    
    Increment q_A by 1
    Decrement q_B by 1
    Add Multiplicity to TotalMultiplicity
    
  Print the total Multiplicity
  
Contains
  
  Define comb(n, r) function
    // Combination function implementation
    
  Define fact(n1) function
    // Factorial function implementation

End Program MultiplicityCalculator

    
Figure 2.4

FORTRAN solution output for Problem 2.9

This concludes the FORTRAN exercise.

Problems with the FORTRAN Code

Similar code structure was implemented in Python and was able to yield the same Total Multiplicity for Problem 2.9, validating its functionality. The Python code successfully ran for both Problem 2.9 and Problem 2.10. However, the FORTRAN code failed to achieve the same Total Multiplicity for Problem 2.10, particularly when handling larger integer numbers.

Problem 2.10

Problem 2.10

Error Msg

FORTRAN compiler error message for Problem 2.10

The error is likely due to the fact that 50! is a very large factorial number, and it exceeds the capacity of the integer variable, resulting in a floating-point error message.

Fixes?

If anyone can find a solution to this problem, please feel free to submit a pull request.

fortran-multiplicity-calculator's People

Contributors

asherchok avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.