summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/lib
diff options
context:
space:
mode:
authorshigek <shigek@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-04-24 13:37:32 +0000
committershigek <shigek@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-04-24 13:37:32 +0000
commitcff57b4a267b61561b04c527b5ce04d64cbcf78b (patch)
tree1196b15571b715ea69fee1ea90ce8bb2e958e787 /ext/bigdecimal/lib
parent558c428b72e666a58d6819cb45b63e75f15ae537 (diff)
Dir. rearrangement according to the suggestions from Minero Aoki.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/lib')
-rw-r--r--ext/bigdecimal/lib/linear.rb46
-rw-r--r--ext/bigdecimal/lib/nlsolve.rb38
-rw-r--r--ext/bigdecimal/lib/pai.rb49
3 files changed, 0 insertions, 133 deletions
diff --git a/ext/bigdecimal/lib/linear.rb b/ext/bigdecimal/lib/linear.rb
deleted file mode 100644
index f93404fb6f..0000000000
--- a/ext/bigdecimal/lib/linear.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/usr/local/bin/ruby
-
-#
-# linear.rb
-#
-# Solves linear equation system(A*x = b) by LU decomposition method.
-# where A is a coefficient matrix,x is an answer vector,b is a constant vector.
-#
-require "bigdecimal"
-require "ludcmp"
-
-include LUSolve
-
-def rd_order
- printf("Number of equations ?")
- n = gets().chomp.to_i
-end
-
-zero = BigDecimal::new("0.0")
-one = BigDecimal::new("1.0")
-
-while (n=rd_order())>0
- a = []
- as= []
- b = []
- printf("\nEnter coefficient matrix element A[i,j]\n");
- for i in 0...n do
- for j in 0...n do
- printf("A[%d,%d]? ",i,j); s = gets
- a <<=BigDecimal::new(s);
- as<<=BigDecimal::new(s);
- end
- printf("Contatant vector element b[%d] ? ",i);b<<=BigDecimal::new(gets);
- end
- printf "ANS="
- x = lusolve(a,b,ludecomp(a,n,zero,one),zero)
- p x
- printf "A*x-b\n"
- for i in 0...n do
- s = zero
- for j in 0...n do
- s = s + as[i*n+j]*x[j]
- end
- p s-b[i]
- end
-end
diff --git a/ext/bigdecimal/lib/nlsolve.rb b/ext/bigdecimal/lib/nlsolve.rb
deleted file mode 100644
index 08f17f9ecd..0000000000
--- a/ext/bigdecimal/lib/nlsolve.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/local/bin/ruby
-
-#
-# nlsolve.rb
-# An example for solving nonlinear algebraic equation system.
-#
-
-require "bigdecimal"
-require "newton"
-include Newton
-
-class Function
- def initialize()
- @zero = BigDecimal::new("0.0")
- @one = BigDecimal::new("1.0")
- @two = BigDecimal::new("2.0")
- @ten = BigDecimal::new("10.0")
- @eps = BigDecimal::new("1.0e-16")
- end
- def zero;@zero;end
- def one ;@one ;end
- def two ;@two ;end
- def ten ;@ten ;end
- def eps ;@eps ;end
- def values(x) # <= defines functions solved
- f = []
- f1 = x[0]*x[0] + x[1]*x[1] - @two # f1 = x**2 + y**2 - 2 => 0
- f2 = x[0] - x[1] # f2 = x - y => 0
- f <<= f1
- f <<= f2
- f
- end
-end
- f = BigDecimal::limit(100)
- f = Function.new
- x = [f.zero,f.zero] # Initial values
- n = nlsolve(f,x)
- p x
diff --git a/ext/bigdecimal/lib/pai.rb b/ext/bigdecimal/lib/pai.rb
deleted file mode 100644
index 4e2dd7104a..0000000000
--- a/ext/bigdecimal/lib/pai.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/usr/local/bin/ruby
-
-#
-# pai.rb
-#
-
-require "bigdecimal"
-#
-# Calculates 3.1415.... using J. Machin's formula.
-#
-def pai(sig) # sig: Number of significant figures
- exp = -sig
- pi = BigDecimal::new("0")
- two = BigDecimal::new("2")
- m25 = BigDecimal::new("-0.04")
- m57121 = BigDecimal::new("-57121")
-
- u = BigDecimal::new("1")
- k = BigDecimal::new("1")
- w = BigDecimal::new("1")
- t = BigDecimal::new("-80")
- while (u.exponent >= exp)
- t = t*m25
- u,r = t.div(k,sig)
- pi = pi + u
- k = k+two
- end
-
- u = BigDecimal::new("1")
- k = BigDecimal::new("1")
- w = BigDecimal::new("1")
- t = BigDecimal::new("956")
- while (u.exponent >= exp )
- t,r = t.div(m57121,sig)
- u,r = t.div(k,sig)
- pi = pi + u
- k = k+two
- end
- pi
-end
-
-if $0 == __FILE__
- if ARGV.size == 1
- print "PAI("+ARGV[0]+"):\n"
- p pai(ARGV[0].to_i)
- else
- print "TRY: ruby pai.rb 1000 \n"
- end
-end