Professional Documents
Culture Documents
Exponential Fit
Exponential Fit
implicit none
integer, external :: getInteger
integer :: numberOfDataPoints
real, dimension(:), allocatable :: x, y
real :: slope, yIntercept
real :: b, m
integer :: dataPointCounter
numberOfDataPoints = getInteger("Enter number of data points.")
allocate(x(numberOfDataPoints))
allocate(y(numberOfDataPoints))
do dataPointCounter = 1, numberOfDataPoints
write(*,*) "Enter data point", dataPointCounter
read(*,*) x(dataPointCounter)
read(*,*) y(dataPointCounter)
end do
write(*,*) "Original data"
do dataPointCounter = 1, numberOfDataPoints
write(*,*) x(dataPointCounter), y(dataPointCounter)
end do
do dataPointCounter = 1, numberOfDataPoints
y(dataPointCounter) = log(y(dataPointCounter))
end do
write(*,*) "Modified (Linearized) data"
do dataPointCounter = 1, numberOfDataPoints
write(*,*) x(dataPointCounter), y(dataPointCounter)
end do
call leastSquares2(x, y, numberOfDataPoints, slope, yIntercept)
m = slope
b = exp(yIntercept)
write(*,*) "Form of the function: y = b * exp(mx)"
write(*,*) "m = ", m
write(*,*) "b = ", b
deallocate(x)
deallocate(y)
end subroutine exponentialFit