A repository of my efforts to learn fortran with python scripts to plot the results
git clone https://github.com/AdamZettel/fortran-fortress.git
cd fortran-fortress/numerical
gfortran monte_carlo_pi.f90 -o monte_carlo_pi
./monte_carlo_pi
python3 plot_monte_carlo_pi.py
- newton-raphson
- euler
- euler-maruyama
- monte carlo calculation of pi
- geometric series
- linear regression (one variable)
These programs show the basics of Fortran syntax
program hello_world
print *, "Hello, World!"
end program hello_world
program simple_addition
implicit none
integer :: a, b, sum
a = 5
b = 10
sum = a + b
print *, "The sum of ", a, " and ", b, " is ", sum
end program simple_addition
program variable_declaration
implicit none
integer, parameter :: dp = kind(1.0d0)
integer :: int_var
real(dp) :: real_var
character(len=20) :: char_var
int_var = 1
real_var = 1.5_dp
char_var = 'a'
print *, "Integer: ", int_var
print *, "Real (dp): ", real_var
print *, "Character: ", char_var
end program variable_declaration
program input_output
implicit none
integer :: num
print *, "Enter an integer (press enter after you type it):"
read *, num
print *, "You entered: ", num
end program input_output
program arithmetic_operations
implicit none
integer, parameter :: dp = kind(1.0d0)
real(dp) :: a, b, sum, difference, product, quotient
a = 12.5_dp
b = 3.5_dp
sum = a + b
difference = a - b
product = a * b
quotient = a / b
print *, "Sum: ", sum
print *, "Difference: ", difference
print *, "Product: ", product
print *, "Quotient: ", quotient
end program arithmetic_operations
program temperature_conversion
implicit none
integer, parameter :: dp = kind(1.0d0)
real(dp) :: celsius, fahrenheit
print *, "Enter temperature in Celsius:"
read *, celsius
fahrenheit = celsius * 9.0_dp / 5.0_dp + 32.0_dp
print *, "Temperature in Fahrenheit: ", fahrenheit
end program temperature_conversion
program simple_interest
implicit none
integer, parameter :: dp = kind(1.0d0)
real(dp) :: principal, rate, time, interest
print *, "Enter principal amount:"
read *, principal
print *, "Enter annual interest rate (in percentage):"
read *, rate
print *, "Enter time (in years):"
read *, time
interest = principal * rate * time / 100.0_dp
print *, "Simple Interest: ", interest
end program simple_interest
program quadratic_equation_solver
implicit none
integer, parameter :: dp = kind(1.0d0)
real(dp) :: a, b, c, discriminant, root1, root2
print *, "Enter coefficients a, b, and c:"
read *, a, b, c
discriminant = b**2 - 4.0 * a * c
if (discriminant < 0.0) then
print *, "The equation has no real roots."
else
root1 = (-b + sqrt(discriminant)) / (2.0 * a)
root2 = (-b - sqrt(discriminant)) / (2.0 * a)
print *, "The roots are: ", root1, " and ", root2
end if
end program quadratic_equation_solver
program bmi_calculator
implicit none
integer, parameter :: dp = kind(1.0d0)
real(dp) :: weight, height, bmi
print *, "Enter weight in kilograms:"
read *, weight
print *, "Enter height in meters:"
read *, height
bmi = weight / (height**2)
print *, "Body Mass Index (BMI): ", bmi
end program bmi_calculator
program area_of_circle
implicit none
integer, parameter :: dp = kind(1.0d0)
real(dp) :: radius, area
real, parameter :: pi = 3.14159
print *, "Enter the radius of the circle:"
read *, radius
area = pi * radius**2
print *, "Area of the circle: ", area
end program area_of_circle