lib/numru/derivative.rb in gphys-1.5.0 vs lib/numru/derivative.rb in gphys-1.5.1
- old
+ new
@@ -151,10 +151,12 @@
raise ArgumentError,"dim value(#{dim}) must be between 0 and (#{z.rank-1}"
end
raise ArgumentError,"rank of x (#{x.rank}) must be 1" if x.rank != 1
# <<expand boundaries>>
ze = b_expand(z,dim,bc)
+ x = x - x[0]
+ x = x.to_type(z.typecode) if (x.typecode < z.typecode)
xe = b_expand_linear_ext(x,0) # always linear extention
# <<differenciation>>
to_rankD = [1]*dim + [true] + [1]*(ze.rank-1-dim) # to exand 1D to rank D
dx = xe[1..-1] - xe[0..-2] # x_{i} - x_{i-1} (for i=0..n-2)
dx2 = dx**2
@@ -175,10 +177,12 @@
dim += z.rank if dim<0
raise ArgumentError,"dim value (#{dim}) must be smaller than z.rank and >= 0" if dim >= z.rank || dim<0
raise ArgumentError,"rank of x (#{x.rank}) must be 1" if x.rank != 1
# <<expand boundary>>
ze = b_expand(z,dim,bc)
+ x = x - x[0]
+ x = x.to_type(z.typecode) if (x.typecode < z.typecode)
xe = b_expand_linear_ext(x,0) # expand boundary of axis.
# <<difference operation>>
dz = cdiff(ze,dim)
dx = cdiff(xe,0)
if dx.rank != dz.rank # make dx.rank == dz.rank
@@ -195,9 +199,11 @@
raise ArgumentError,"dim value(#{dim}) must be between 0 and (#{z.rank-1}"
end
raise ArgumentError,"rank of x (#{x.rank}) must be 1" if x.rank != 1
# <<expand boundaries>>
ze = b_expand(z,dim,bc)
+ x = x - x[0]
+ x = x.to_type(z.typecode) if (x.typecode < z.typecode)
xe = b_expand_linear_ext(x,0) # always linear extention
# <<differenciation>>
to_rankD = [1]*dim + [true] + [1]*(ze.rank-1-dim) # to exand 1D to rank D
dx20 = xe[2..-1] - xe[0..-3] # x_{i+1} - x_{i-1} (for i=1..-2)
dx21 = xe[2..-1] - xe[1..-2] # x_{i+1} - x_{i} (for i=1..-2)