Annotation of OpenXM_contrib/gnuplot/demo/bivariat.dem, Revision 1.1
1.1 ! maekawa 1: #
! 2: # $Id: bivariat.dem,v 1.2 1993/09/27 17:11:14 alex Exp $
! 3: #
! 4: # This demo is very slow and requires unusually large stack size.
! 5: # Do not attempt to run this demo under MSDOS.
! 6: #
! 7:
! 8: # the function integral_f(x) approximates the integral of f(x) from 0 to x.
! 9: # integral2_f(x,y) approximates the integral from x to y.
! 10: # define f(x) to be any single variable function
! 11: #
! 12: # the integral is calculated as the sum of f(x_n)*delta
! 13: # do this x/delta times (from x down to 0)
! 14: #
! 15: f(x) = exp(-x**2)
! 16: delta = 0.2
! 17: # delta can be set to 0.025 for non-MSDOS machines
! 18: #
! 19: # integral_f(x) takes one variable, the upper limit. 0 is the lower limit.
! 20: # calculate the integral of function f(t) from 0 to x
! 21: integral_f(x) = (x>0)?integral1a(x):-integral1b(x)
! 22: integral1a(x) = (x<=0)?0:(integral1a(x-delta)+delta*f(x))
! 23: integral1b(x) = (x>=0)?0:(integral1b(x+delta)+delta*f(x))
! 24: #
! 25: # integral2_f(x,y) takes two variables; x is the lower limit, and y the upper.
! 26: # claculate the integral of function f(t) from x to y
! 27: integral2_f(x,y) = (x<y)?integral2(x,y):-integral2(y,x)
! 28: integral2(x,y) = (x>y)?0:(integral2(x+delta,y)+delta*f(x))
! 29:
! 30: set autoscale
! 31: set title "approximate the integral of functions"
! 32: set samples 50
! 33:
! 34: plot [-5:5] f(x) title "f(x)=exp(-x**2)", 2/sqrt(pi)*integral_f(x) title "erf(x)=2/sqrt(pi)*integral_f(x)"
! 35:
! 36: pause -1 "Hit return to continue"
! 37:
! 38: f(x)=sin(x)
! 39:
! 40: plot [-5:5] f(x) title "f(x)=sin(x)", integral_f(x)
! 41:
! 42: pause -1 "Hit return to continue"
! 43:
! 44: set title "approximate the integral of functions (upper and lower limits)"
! 45:
! 46: f(x)=(x-2)**2-20
! 47:
! 48: plot [-10:10] f(x) title "f(x)=(x-2)**2-20", integral2_f(-5,x)
! 49:
! 50: pause -1 "Hit return to continue"
! 51:
! 52: f(x)=sin(x-1)-.75*sin(2*x-1)+(x**2)/8-5
! 53:
! 54: plot [-10:10] f(x) title "f(x)=sin(x-1)-0.75*sin(2*x-1)+(x**2)/8-5", integral2_f(x,1)
! 55:
! 56: pause -1 "Hit return to continue"
! 57:
! 58: #
! 59: # This definition computes the ackermann. Do not attempt to compute its
! 60: # values for non integral values. In addition, do not attempt to compute
! 61: # its beyond m = 3, unless you want to wait really long time.
! 62:
! 63: ack(m,n) = (m == 0) ? n + 1 : (n == 0) ? ack(m-1,1) : ack(m-1,ack(m,n-1))
! 64:
! 65: set xrange [0:3]
! 66: set yrange [0:3]
! 67:
! 68: set isosamples 4
! 69: set samples 4
! 70:
! 71: set title "Plot of the ackermann function"
! 72:
! 73: splot ack(x, y)
! 74:
! 75: pause -1 "Hit return to continue"
! 76:
! 77: set xrange [-5:5]
! 78: set yrange [-10:10]
! 79: set isosamples 10
! 80: set samples 100
! 81: set key 4,-3
! 82: set title "Min(x,y) and Max(x,y)"
! 83:
! 84: #
! 85: min(x,y) = (x < y) ? x : y
! 86: max(x,y) = (x > y) ? x : y
! 87:
! 88: plot sin(x), x**2, x**3, max(sin(x), min(x**2, x**3))+0.5
! 89:
! 90: pause -1 "Hit return to continue"
! 91:
! 92: #
! 93: # gcd(x,y) finds the greatest common divisor of x and y,
! 94: # using Euclid's algorithm
! 95: # as this is defined only for integers, first round to the nearest integer
! 96: gcd(x,y) = gcd1(rnd(max(x,y)),rnd(min(x,y)))
! 97: gcd1(x,y) = (y == 0) ? x : gcd1(y, x - x/y * y)
! 98: rnd(x) = int(x+0.5)
! 99:
! 100: set samples 59
! 101: set xrange [1:59]
! 102: set auto
! 103: set key
! 104:
! 105: set title "Greatest Common Divisor (for integers only)"
! 106:
! 107: plot gcd(x, 60)
! 108: pause -1 "Hit return to continue"
! 109:
! 110: set xrange [-10:10]
! 111: set yrange [-10:10]
! 112: set auto
! 113: set isosamples 10
! 114: set samples 100
! 115: set title ""
! 116:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>