http://www.math.grin.edu/~rebelsky/Courses/397/98S/
time
and /bin/time
to time
your programs.
public static void main(String args[]) { double d = 0.0; for (double n = 0.0; n < 1001.0; n = n + 1.0) { d += n; } } // main
n=1
instead of
n=0
.
and then "fill down"| A | B | C | D 01 Year Value R 02 0 I 03 =A1+1 =B2*(1+$C$1)
pv
function in your spreadsheet
or calculator.
public static float presentValue(float investment, float rate, int years) { float interest; for (int i = 0; i < years; ++i) { // Compute this year's interest interest = investment*rate; // Update the investment investment = investment + interest; } // for return investment; } // presentValue
exponent()
function. This compartmentalizes
the program, and lets us think about future improvments.
/** * Compute x^n for double x and integer n * pre: n >= 0 * pre: x > 0 * pre: x^n < maxdouble (can't really check this, but ...) * post: returns x^n */ public double exp(double x, int n) { double tmp; // Used for intermediate calculations if (n == 0) { // x^0 = 1 for x != 0 return 1.0; } // n is 0 else if (even(n)) { // x^(2k) = x^k * x^k tmp = exp(x, n/2); return tmp*tmp; } // n is even else { // n is odd // x^(k+1) = x * x^k tmp = exp(x, n-1); return x*tmp; } // n is odd } // exp
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
Source text last modified Tue Nov 4 10:12:21 1997.
This page generated on Tue Nov 4 14:21:39 1997 by SiteWeaver.
Contact our webmaster at rebelsky@math.grin.edu