Python多项式类实现与测试

49、编写一个名为 add_point 的方法,该方法接受一个多项式 q 和一个元组 (x, y) 作为参数,并返回一个对 self.points 和 (x, y) 进行插值的新多项式。

下面是给定的【文本内容】:

```python
import numpy as np

class PolyNomial:
    base ='monomial'
    def __init__(self, **args):
        if 'points' in args:
            self.points = np.array(args['points'])
            self.xi = self.points[:, 0]
            self.coeff = self.point_2_coeff()
            self.degree = len(self.coeff) - 1
        elif 'coeff' in args:
            self.coeff = np.array(args['coeff'])
            self.degree = len(self.coeff) - 1
            self.points = self.coeff_2_point()
        else:
            self.points = np.array([[0, 0]])
            self.xi = np.array([1.])
            self.coeff = self.point_2_coeff()
            self.degree = 0

    def point_2_coeff(self):
        import scipy.linalg as sl
        return sl.solve(np.vander(self.xi), self.points[:, 1])

    def coeff_2_point(self):
        from numpy import lins
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值