Mediant approximation trick

近似值的一个取值技巧

如果知道一个数值变量的上限和下限,那么有一种快速的方法,快速获取该变量更准确的近似值。

比如,已知变量e的大小范围是19/7 < e < 87/32,就可以快速得到它的近似值。

Suppose you are trying to approximate some number x and you’ve got it sandwiched between two rational numbers:

a/b < x < c/d.

Now you’d like a better approximation. What would you do?

The obvious approach would be to take the average of a/b and c/d. That’s fine, except it could be a fair amount of work if you’re doing this in your head.

I recently stumbled across an article [1] that suggested taking the mediant of the two fractions rather than the mean. The mediant of two fractions simply adds the numerators and denominators, the very thing you might have gotten your hand slapped for doing in elementary school. It’s not a valid way to add two fractions, but it is a valid way to get a new fraction between two fractions. That is,

a/b < (a + c)/(b + d) < c/d.

So the mediant of a lower bound and an upper bound is going to be a better approximation than either bound.

There are two advantages to using the mediant rather than the mean:

  1. It’s easier to compute mentally.
  2. It generally results in smaller numerators and denominators.

For example, suppose you know that 19/7 and 87/32 are both approximations to e, with

19/7 < e < 87/32.

Then (19 + 87)/(7 + 32) = 106/39 should be better than either of the previous approximations.

Here’s a little Python calculation to illustrate that this is the case.

    >>> from math import exp>>> e = exp(1)>>> 19/7 - e-0.003996114173330678>>> 87/32 - e0.0004681715409549092>>> 106/39 - e-0.0003331105103270282

So 106/39 is an order of magnitude more accurate an approximation to e than 19/7 is. The approximation 106/39 is also more accurate than 87/32, though it’s not as much an improvement over 87/32 as it was over 19/7.

You might notice that while 87/32 overestimates e, 106/39 underestimates e, and by roughly the same amount. This suggests repeating our process would give an even better approximation. Let’s check it out.

The mediant of 87/32 and 106/39 is 193/71.

    >>> 193/71 - e2.8030695884417867e-05

This shows that 193/71 is an order of magnitude better than 106/39 as an approximation to e.

Here’s a plot of the last three approximations.

好图

Related posts

  • Mentally computing mathematical functions
  • Mentally calculating day of the week in 2023

[1] Tom M. Apostol and Mamikon A. Mnatsakanian. Good Rational Approximations to Logarithms. The College Mathematics Journal, May, 2001, Vol. 32, No. 3. pp. 172–179.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/330108.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

RIS 辅助无线网络:基于模型、启发式和机器学习优化方法

目录 abstractintroduction相关研究BACKGROUND AND PROBLEM FORMULATIONS FOR OPTIMIZING RIS-AIDED WIRELESS NETWORKSA 优化RIS-AIDED无线网络的背景和问题公式RIS操作原则&#xff1a;RIS控制&#xff1a;RIS部署 B 总速率/容量最大化C 功率最小化D 能源效率最大化E 用户公平…

JavaScript基础(24)_dom查询练习(一)

<!DOCTYPE html> <html lang"zh"> <head><meta charset"UTF-8"><link rel"stylesheet" href"../browser_default_style/reset.css"><title>dom查询练习一</title><style>.text {widt…

【STM32】PWR电源控制

1 PWR简介 PWR&#xff08;Power Control&#xff09;电源控制 PWR负责管理STM32内部的电源供电部分&#xff0c;可以实现可编程电压监测器和低功耗模式的功能 可编程电压监测器&#xff08;PVD&#xff09;可以监控VDD电源电压&#xff0c;当VDD下降到PVD阀值以下或上升到P…

在 Linux 中开启 Flask 项目持续运行

在 Linux 中开启 Flask 项目持续运行 在部署 Flask 项目时&#xff0c;情况往往并不是那么理想。默认情况下&#xff0c;关闭 SSH 终端后&#xff0c;Flask 服务就停止了。这时&#xff0c;您需要找到一种方法在 Linux 服务器上实现持续运行 Flask 项目&#xff0c;并在服务器…

Redis内存策略:「过期Key删除策略」+ 「内存淘汰策略」

Redis之所以性能强&#xff0c;最主要的原因就是基于内存存储&#xff0c;然而单节点的Redis其内存大小不宜过大&#xff0c;否则会影响持久化或主从同步的性能。 Redis内存满了&#xff0c;会发生什么&#xff1f; 在Redis的运行内存达到了某个阈值&#xff0c;就会触发内存…

olap/spark-tungsten:codegen

15721这一章没什么好说的&#xff0c;不再贴课程内容了。codegen和simd在工业界一般只会选一种实现。比如phothon之前用codegen&#xff0c;然后改成了向量化引擎。一般gen的都是weld IR/LLVM IR/当前语言&#xff0c;gen成C的也要检查是不是有本地预编译版本&#xff0c;要不没…

实战环境搭建-linux下安装mysql

下载wget命令 yum -y install wget 在线下载mysql安装包 wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 安装的过程中有可能出现秘钥过期,如下图: 解决办法: rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 再次安装,如下…

leetcode动态规划问题总结 Python

目录 一、基础理论 二、例题 1. 青蛙跳台阶 2. 解密数字 3. 最长不含重复字符的子字符串 4. 连续子数组的最大和 5. 最长递增子序列 6. 最长回文字符串 7. 机器人路径条数 8. 礼物的最大价值 一、基础理论 动态规划其实是一种空间换时间的基于历史数据的递推算法&…

【airsim】两分钟,用python脚本获取虚拟数据集

现有的教程在配置基于python的airsim环境过程中&#xff0c;都要求执行完整的编译步骤。然而&#xff0c;在linux和windows上的编译过程中会遇到诸多问题&#xff0c;大概需要半天左右时间。 如果你只是想采集一些数据&#xff0c;测试一下虚拟数据的效果&#xff0c;那么解决…

【分布式】分布式链路跟踪技术

为什么需要分布式链路追踪 提到分布式链路追踪&#xff0c;我们要先提到微服务。相信很多人都接触过微服务。微服务是一种开发软件的架构和组织方法&#xff0c;它侧重将服务解耦&#xff0c;服务之间通过API通信。使应用程序更易于扩展和更快地开发&#xff0c;从而加速新功能…

【Python从入门到进阶】46、58同城Scrapy项目案例介绍

接上篇《45、Scrapy框架核心组件介绍》 上一篇我们学习了Scrapy框架的核心组件的使用。本篇我们进入实战第一篇&#xff0c;以58同城的Scrapy项目案例&#xff0c;结合实际再次巩固一下项目结构以及代码逻辑的用法。 一、案例网站介绍 58同城是一个生活服务类平台&#xff0c…

qt-C++笔记之QProcess

qt-C笔记之QProcess code review! 文章目录 qt-C笔记之QProcess一.示例&#xff1a;QProcess来执行系统命令ls -l命令并打印出结果说明 二.示例&#xff1a;QProcess来执行系统命令ls -l命令并打印出结果&#xff0c;代码进一步丰富三.示例&#xff1a;使用 QProcess 在 Qt 中…