- #1

- 23

- 0

## Homework Statement

The course is Computational Physics, but in a sense this is a pretty straight computer science or even mathematical challenge.

The first part of the assignment - the relatively easy part - was to write a Fortran program to take two variables - the number to which e should be raised, and the number of iterations of the Taylor series to use in approximating it.

The Taylor series includes the factorial of the iteration number, so a subroutine had to be written to calculate the factorial.

Got all that up and running, without too much trouble.

## Homework Equations

e

^{x}≈ Ʃ x

^{i}/i! where x is the number to evaluate. i runs from 0 to n-1, where n is the number of iterations specified.

And then there's the definition of the factorial...

## The Attempt at a Solution

The second, harder (bonus marks) part of the question is to write a program that takes the same input for the number to be exponentiated, but takes another number, dx. The program should keep evaluating the Taylor Series approximation until it is less than dx away from the true value, obtained using Fortrans exp(x) intrinsic function.

The main problem I'm having is how to calculate the factorial in a loop when the upper bound keeps changing. I don't need you to write out detailed Fortran code, just some suggestions or pseudocode about how to do this calculation with these specifications.