双线性插值,英文也叫 Bilinear Interpolation 是个对数据非常不错拟合方法.可以想像成在二维网格下对X和Y方向上的两次插值.具体的公式什么的就不多说了,可以参见维基百科
这个插值方法估计很多做研究的都需要用上(当然我不使用matlab), 于是我把公式翻译成C/C++函数, 欢迎使用.如果精度不够,可以改成 双精度 double 类型.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | // https://helloacm.com inline float BilinearInterpolation(float q11, float q12, float q21, float q22, float x1, float x2, float y1, float y2, float x, float y) { float x2x1, y2y1, x2x, y2y, yy1, xx1; x2x1 = x2 - x1; y2y1 = y2 - y1; x2x = x2 - x; y2y = y2 - y; yy1 = y - y1; xx1 = x - x1; return 1.0 / (x2x1 * y2y1) * ( q11 * x2x * y2y + q21 * xx1 * y2y + q12 * x2x * yy1 + q22 * xx1 * yy1 ); } |
// https://helloacm.com inline float BilinearInterpolation(float q11, float q12, float q21, float q22, float x1, float x2, float y1, float y2, float x, float y) { float x2x1, y2y1, x2x, y2y, yy1, xx1; x2x1 = x2 - x1; y2y1 = y2 - y1; x2x = x2 - x; y2y = y2 - y; yy1 = y - y1; xx1 = x - x1; return 1.0 / (x2x1 * y2y1) * ( q11 * x2x * y2y + q21 * xx1 * y2y + q12 * x2x * yy1 + q22 * xx1 * yy1 ); }
强烈推荐
- 英国代购-畅购英伦
- TopCashBack 返现 (英国购物必备, 积少成多, 我2年来一共得了3000多英镑)
- Quidco 返现 (也是很不错的英国返现网站, 返现率高)
- 注册就送10美元, 免费使用2个月的 DigitalOcean 云主机(性价比超高, 每月只需5美元)
- 注册就送10美元, 免费使用4个月的 Vultr 云主机(性价比超高, 每月只需2.5美元)
- 注册就送10美元, 免费使用2个月的 阿里 云主机(性价比超高, 每月只需4.5美元)
- 注册就送20美元, 免费使用4个月的 Linode 云主机(性价比超高, 每月只需5美元) (折扣码: PodCastInit2022)
- PlusNet 英国光纤(超快, 超划算! 用户名 doctorlai)
- 刷了美国运通信用卡一年得到的积分 换了 485英镑
- 注册就送50英镑 – 英国最便宜最划算的电气提供商
- 能把比特币莱特币变现的银行卡! 不需要手续费就可以把虚拟货币法币兑换
微信公众号: 小赖子的英国生活和资讯 JustYYUK