【转载】interpolation(插值)和 extrapolation(外推)的区别

  根据已有数据以及模型(函数)预测未知区域的函数值,预测的点在已有数据范围内就是interpolation(插值),

范围外就是extrapolation(外推)。

The Difference Between Extrapolation and Interpolation

 

 

figure:  The left is an example of interpolation and the right is an example of extrapolation.

转载于:https://www.cnblogs.com/tlz888/p/11434682.html

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
插值interpolation)和extrapolation)是两种常见的数值计算方法,其中插值是通过已知的数据点来计算未知点的值,而是利用已知的数据点来计算超出已知数据范围的点的值。 在C++中,可以使用一些库来实现插值。例如,使用Boost库中的interpolate函数可以实现多项式插值和线性插值。以下是一个使用Boost库进行线性插值的示例代码: ```c++ #include <iostream> #include <boost/math/interpolators/linear.hpp> int main() { std::vector<double> x{1, 2, 3, 4}; std::vector<double> y{1, 4, 9, 16}; boost::math::interpolators::linear<double> interp(x.begin(), x.end(), y.begin()); double z = interp(2.5); // 计算x=2.5时的插值结果 std::cout << "Interpolated value at x=2.5 is " << z << std::endl; return 0; } ``` 对于,可以使用类似的方法进行实现。例如,假设我们已知函数f(x)=1/x,在x=1处的函数值为1,我们可以使用线性插值来计算在x=0时的函数值: ```c++ #include <iostream> #include <boost/math/interpolators/linear.hpp> int main() { std::vector<double> x{1}; std::vector<double> y{1}; boost::math::interpolators::linear<double> interp(x.begin(), x.end(), y.begin()); double z = interp(0); // 计算x=0时的插值结果 std::cout << "Extrapolated value at x=0 is " << z << std::endl; return 0; } ``` 需要注意的是,通常比插值更不可靠,因为我们无法保证我们的结果与真实值有多接近。因此,在进行时需要谨慎处理,最好只对已知的数据范围进行插值

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值