Python可以帮忙:)

# 这让我想起了用JavaScript做欧拉公式和梯形公式计算的事情

# 功能实用,性能嘛,再说吧,典型的行为学派观点^^

# 线性插值(并做乘积)

import decimal

def _process(bf, cf):
    '''
    Process the data and return its result
    '''
    lis = []
    i = 0
    j = 0

    decimal.getcontext().prec = 11
    _b = [(decimal.Decimal(line[9:25]), decimal.Decimal(line[34:50])) for line in open(bf) if len(line) == 65]
    _c = [(decimal.Decimal(line[9:25]), decimal.Decimal(line[34:50])) for line in open(cf) if len(line) == 65]

    while 1:
        try:
            if _c[j][0] < _b[i][0]:
                j += 1
                if _c[j][0] >= _b[i][0]:
                    _v = _b[i][1]*(_c[j-1][1]+(_b[i][0]-_c[j-1][0])*(_c[j][1]-_c[j-1][1])/(_c[j][0]-_c[j-1][0]))
                    lis.append((_b[i][0], _v))
                    i += 1
                    j -= 1
            else:
                _v = _b[i][1]*(_c[j][1]+(_b[i][0]-_c[j][0])*(_c[j+1][1]-_c[j][1])/(_c[j+1][0]-_c[j][0]))
                lis.append((_b[i][0], _v))
                i += 1
        except IndexError:
            # print 'Done!'
            break

    return lis

base data file: 244(slice)
plot points:

             x                        y                   e

         5.0002500125E-04         4.8430921737E-01      0.54177
         1.5000750038E-03         3.0355905909E+00      0.18986
         2.5001250063E-03         3.7486307653E+00      0.16132
         3.5001750088E-03         6.5356686466E+00      0.12887
         4.5002250113E-03         7.9923502044E+00      0.09901

compared data file: m2(slice)
plot points:

             x                        y                   e

         1.0000000000E-11         2.4814747679E+02      0.00000
         1.1543570000E-11         2.3116622757E+02      0.00000
         1.1660930000E-11         2.3003818964E+02      0.00000
         1.3087150000E-11         2.1727277313E+02      0.00000
         1.3321870000E-11         2.1543349880E+02      0.00000

test:
>>> from process import _process as p
>>> res = p('244', 'm2')
>>> len(res)
19999
>>> res[0]
(Decimal('0.00050002500125'), Decimal('4.9097028328'))
>>> sum = 0
>>> for r in res:
...     sum += r[1]
...
>>> print sum
200601.01471


转载于:https://my.oschina.net/gurdy/blog/17413

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值