MathLab> octave Octave, version 1.1.1. Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton. This is free software with ABSOLUTELY NO WARRANTY. For details, type `warranty'.
octave:1> # octave:1> # Comment: Define Integrand: octave:1> function y = f (x) > y=exp(-x*x); > endfunction
octave:2> # octave:2> # Integral for x on (0,1): octave:2> [area,ierror,nfneval]=quad("f",0,1) area = 0.74682 ierror = 0 nfneval = 21 octave:3> # Comment: Here "area" is the answer, "ierror" is the error code, octave:3> # and "nfneval" is the number of function evaluations.
octave:3> # Comment: Integral for x on (0,Inf): octave:3> [area,ierror,nfneval]=quad("f",0,Inf) area = 0.88623 ierror = 0 nfneval = 135
octave:4> # octave:4> # Comment: Refined Answer Recovering "area" to 10 Digits using "prinf": octave:4> printf("Refined answer to 10 digits = %12.10f\n",area); Refined answer to 10 digits = 0.8862269255 octave:5> # Comment: Here the format "%w.pf" means "p" "f"loating digits in a field of octave:5> # width "w" using the C language "printf" function borrowed by Octave.
octave:5> # octave:5> # Comment: Check Integral on (0,Inf) Against Exact Answer: octave:5> Error=(area-sqrt(pi)/2)*2/sqrt(pi) Error = 0 octave:6> # Comment: Error to 40 digits: octave:6> printf("Refined Error to 40 digits = %42.40f\n",Error); Refined Error to 40 digits = 0.0000000000000000000000000000000000000000
octave:22> quit MathLab>
Email Comments or Questions to hanson@math.uic.edu