コード例 #1
0
    def _gauss_lobatto_conditioning_helper(self, num_nodes,
                                           zero_centered=False):
        import numpy as np
        from assignment1.dg1 import gauss_lobatto_points

        all_nodes = gauss_lobatto_points(-1.0, 1.0, num_nodes)
        self.assertEqual(all_nodes[0], -1.0)
        self.assertEqual(all_nodes[-1], 1.0)
        inner_nodes = all_nodes[1:-1]
        if zero_centered:
            x_vals = np.hstack([[-1], inner_nodes, [1]])
        else:
            # Translate [-1, 1] --> [0, 2] --> [0, 1]
            x_vals = np.hstack([[0], 0.5 * (1 + inner_nodes), [1]])
        leg_mat = self._call_func_under_test(x_vals)
        kappa2 = np.linalg.cond(leg_mat, p=2)
        # This gives the exponent of kappa2.
        base_exponent = np.log2(np.spacing(1.0))
        return int(np.round(np.log2(np.spacing(kappa2)) - base_exponent))
コード例 #2
0
 def _call_func_under_test(start, stop, num_points):
     from assignment1.dg1 import gauss_lobatto_points
     return gauss_lobatto_points(start, stop, num_points)