mit 计算机科学及编程导论(5)

本文探讨了在Python中使用浮点数时的常见误解与问题,包括计算机内浮点数表示的局限性、操作导致的误差累积、打印函数的数值舍入以及在比较浮点数时的正确做法。同时强调了培养学生像计算机科学家一样思考的重要性,通过实例展示了改进浮点数计算方法以提高精度与效率的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

words:

confession , auditorium , crunch ,  mirror , budget deficit , considerably , exponentiation , exponent , obnoxious , mantissa , purist , significand , stroll , hence , decimal , pesky ,  fraction , etc==etcetera , approximation , implication , accumulate , drive-home , epsilon , successive , spin , bi-section , logarithm , thoroughly , terminology , predicate ,  fussy , exceed , creep , infamous , constant , equivalent , enormous


notes:

two major parts today : numbers (especially floating point) in python  &  solve problems involved floating point with computer

一、numbers in python

1、some numbers represented in computer is contrary to your intuition suggests  

2、when manipulate floating point , error will grow bigger while the iterating

3、print function prints rounding numbers , so what it prints is not what it is represented in computer

4、worry about "==" on floats : never test the equivalent of floats but how close they are

二、solve problems involved floating point with computer

1、real numbers can't enumerate exhaustively , so we just can guess , check & improve

2、how to improve : successive approximation (in this class professor uses bi-section)

3、what matters the improvement : the speed of the convergence

4、good habits in writing function :  check the arguments & give it a limit bound to the iteration


ps:

1、整个课程就是要培养学生像computer scientists般的思考,所以会覆盖很多用计算机解决问题的方法的讲解。这一次就是讲解如何解决涉及浮点数的问题。当涉及浮点数时要注意计算机内的表示只是约数,所以不能得到精确的值,也就是得到的只是符合某种精度的约数值。而如何利用最快、最省资源的算法去求出约数就是关 键


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值