当前位置: 首页>>代码示例>>Python>>正文


Python Matrix.setValue方法代码示例

本文整理汇总了Python中matrix.Matrix.setValue方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.setValue方法的具体用法?Python Matrix.setValue怎么用?Python Matrix.setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matrix.Matrix的用法示例。


在下文中一共展示了Matrix.setValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_adding_some_values

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import setValue [as 别名]
 def test_adding_some_values(self):
     columns = 2
     rows = 3
     matrix = Matrix(rows, columns)
     matrix.setValue(2, 1, 2)
     matrix.setValue(3, 2, 6)
     self.assertEqual(2, matrix.getValue(2, 1))
     self.assertEqual(6, matrix.getValue(3, 2))
开发者ID:Si-B,项目名称:numericAlgorithms,代码行数:10,代码来源:test_matrix.py

示例2: Spline

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import setValue [as 别名]
class Spline():
    def __init__(self, xValues, yValues, firstDerivate, lastDerivate):
        assert len(xValues) == len(yValues)

        self.xValues = [float(value) for value in xValues]
        self.yValues = yValues
        self.firstDerivate = firstDerivate
        self.lastDerivate = lastDerivate

        self.length = len(xValues)

        self.calculate_lambdas_and_mys()
        self.calculate_ds()

        self.create_matrix()
        #self.cancel_out_bottom_row()
        self.calculate_new_lambdas()
        self.calculate_new_ds()
        self.calculate_Mis()
        self.calculate_coefficients()

    def calculate_lambdas_and_mys(self):
        self.calculate_lambdas()
        self.mys = [False]
        for l in [1 - l for l in self.lambdas[1:]]:
            self.mys.append(l)

        self.mys.append(1)  # myn is always 1 (capter 3 page 33)

    def calculate_lambdas(self):
        self.lambdas = [1]  # lambda0 is always 1 (capter 3 page 33)
        for i in range(1, self.length - 1):
            self.lambdas.append((self.xValues[i + 1] - self.xValues[i]) /
                                (self.xValues[i + 1] - self.xValues[i - 1])
                                )

    def calculate_ds(self):
        xValues = self.xValues
        yValues = self.yValues

        self.ds = []
        self.ds.append(self.calculate_d0())

        for i in range(1, self.length -1):
            firstFraction = 6 / (xValues[i + 1] - xValues[i - 1])

            secondFraction = ((yValues[i + 1] - yValues[i]) /
                              (xValues[i + 1] - xValues[i])
                              )

            thirdFraction = ((yValues[i] - yValues[i - 1]) /
                             (xValues[i] - xValues[i - 1])
                             )

            self.ds.append(firstFraction * (secondFraction - thirdFraction))

        self.ds.append(self.calculate_dn())

    def calculate_d0(self):
        xValues = self.xValues
        yValues = self.yValues
        return 6 / (xValues[1] - xValues[0]) * ((yValues[1] - yValues[0]) /
                                                (xValues[1] - xValues[0])
                                                -self.firstDerivate)

    def calculate_dn(self):
        xValues = self.xValues
        yValues = self.yValues
        return 6 / (xValues[-1] - xValues[-2]) * (self.lastDerivate -
                                                  (yValues[-1] - yValues[-2]) /
                                                  (xValues[-1] - xValues[-2])
                                                  )

    def create_matrix(self):
        self.matrix = Matrix(self.length, self.length)
        #2s
        for i in range(1, self.matrix.rowCount + 1):
            self.matrix.setValue(i, i, 2)

        #lambdas
        for i in range(1, self.matrix.rowCount):
            self.matrix.setValue(i, i + 1, self.lambdas[i - 1])

        #µs
        for i in range(2, self.matrix.rowCount + 1):
            self.matrix.setValue(i, i - 1, self.mys[i -1])

    def calculate_new_lambdas(self):
        self.new_lambdas = []
        self.new_lambdas.append(self.lambdas[0] / 2.0)
        for i in range(1, len(self.lambdas)):
            self.new_lambdas.append(self.lambdas[i] /
                                    (2 - self.new_lambdas[i -1] * self.mys[i])
                                    )

    def calculate_new_ds(self):
        self.new_ds = []
        self.new_ds.append(self.ds[0] / 2.0)
        for i in range(1, len(self.ds)):
            self.new_ds.append((self.ds[i] - self.new_ds[i -1] * self.mys[i])/
#.........这里部分代码省略.........
开发者ID:Si-B,项目名称:numericAlgorithms,代码行数:103,代码来源:spline.py


注:本文中的matrix.Matrix.setValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。