summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/lib/jacobian.rb
diff options
context:
space:
mode:
authorshigek <shigek@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-18 15:24:25 +0000
committershigek <shigek@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-18 15:24:25 +0000
commite242cf9defb5442ef223535abe93399352cf139e (patch)
treeb8eb591e57c326fd4e7cb49365f7e51783179237 /ext/bigdecimal/lib/jacobian.rb
parentb10272dc371a03844f685dc6db765c2bea11d29b (diff)
More pathes from Tadasi Saito.
As discussed in ruby-dev ML: E,PI, etc are disabled. BigDecimal op String disabled. to_f changed. lib directory moved. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/lib/jacobian.rb')
-rw-r--r--ext/bigdecimal/lib/jacobian.rb63
1 files changed, 0 insertions, 63 deletions
diff --git a/ext/bigdecimal/lib/jacobian.rb b/ext/bigdecimal/lib/jacobian.rb
deleted file mode 100644
index 34a60ae67a..0000000000
--- a/ext/bigdecimal/lib/jacobian.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-#
-# jacobian.rb
-#
-# Computes Jacobian matrix of f at x
-#
-module Jacobian
- def isEqual(a,b,zero=0.0,e=1.0e-8)
- aa = a.abs
- bb = b.abs
- if aa == zero && bb == zero then
- true
- else
- if ((a-b)/(aa+bb)).abs < e then
- true
- else
- false
- end
- end
- end
-
- def dfdxi(f,fx,x,i)
- nRetry = 0
- n = x.size
- xSave = x[i]
- ok = 0
- ratio = f.ten*f.ten*f.ten
- dx = x[i].abs/ratio
- dx = fx[i].abs/ratio if isEqual(dx,f.zero,f.zero,f.eps)
- dx = f.one/f.ten if isEqual(dx,f.zero,f.zero,f.eps)
- until ok>0 do
- s = f.zero
- deriv = []
- if(nRetry>100) then
- raize "Singular Jacobian matrix. No change at x[" + i.to_s + "]"
- end
- dx = dx*f.two
- x[i] += dx
- fxNew = f.values(x)
- for j in 0...n do
- if !isEqual(fxNew[j],fx[j],f.zero,f.eps) then
- ok += 1
- deriv <<= (fxNew[j]-fx[j])/dx
- else
- deriv <<= f.zero
- end
- end
- x[i] = xSave
- end
- deriv
- end
-
- def jacobian(f,fx,x)
- n = x.size
- dfdx = Array::new(n*n)
- for i in 0...n do
- df = dfdxi(f,fx,x,i)
- for j in 0...n do
- dfdx[j*n+i] = df[j]
- end
- end
- dfdx
- end
-end