想起了CASIO82es调牛顿解方程


在练打字,看到这个(这可是我手打的~)

-----------------------
examples: square roots by newton's method
----------------------
procedures, as introduced above, are much like ordinary mathematical functions. they specify a value that is determined by one or more parameters. but there is an important difference between mathematical functions and computer procedures. procedures must be effective.

as a case in point, consider the problem of computing square roots. we can define the square-root functions as
...
this describes a perfectly legitimate mathematical function. we could use it to recognize wether one number is the square root of another, or to derive facts about square roots in general. on the other hand, the definition does not describe a procedure. indeed, it tells us almost nothing about how  to actually find the square root of a given number. it will not help matters to rephrase this definition in pseudo-lisp:

(define (sqrt x)
    (the y (and (>= y 0)
           (= (square y) x))))
this only begs the question.

the contrast between function and procedure is a reflection of the general distinction between describing properties of things and describing how to do things, or , as  it is something refered to , the distinction between declarative(whit  is )descriptions, whereas in computer science we are usually concerned with imperative(how to ) descriptions.

how does one compute square roots? the most common way is to use newtos's method of successive approximations, which says that whenever we have a guess y for the value of the square root of a number x, we can perform a simple manipulation to get a better guess ( one  closer to the actual square root) by averaging y with x/y. for examplew, we can compute the square root of 2 as follows. suppose our initial guess is 1:

guess     quotient    average
1     (2/1)=2     ((2+1)/2)=1.5
1.5     (2/1.5)=1.3333    ((1.3333+1.5)/2)=1.4167
1.4167      ...        ...
1.4142     ...        ...

continuing this process, we obtain better and better approximations to the square root.

now let's formative the process in term of procedures. we start with a value for the radicand(the number whose square root we are trying to compute) and a value for the guess. if the guess is good enough for our purposes, we are done; if not, we must repeat the process with an improved  guess. we write this basic strategy as a procedure:

(define (sqrt-iter guess x)
    (if (good-enough? guess x)
        guess
        (sqrt-iter (improve guess x)
                   x)))
A guess is improved by averaging it with the quotient of the radicand and the old guess:

(define (improve guess x)
    (average guess (/ x guess)))

where

(define (average x y)
    (/ (+ x y) 2))

we also have to say what we mean by "good enough," the following will do for illustration, but it is nott really a very good test. the idea is to improve the answer until it is close enough so that its square differs from the radicand by less than a predetermined tolerance.

(define (good-enough? guess x)
    (< (abs (- (square guess) x)) 0.001))
finally, we need a way to get started. for instance, we can always guess that the square root of any number is 1.

(define (sqrt x)
    (sqrt-iter 1.0 x))

if we type these definitions to te interpreter, we can use sqrt just as we can use any procedure:

(sqrt 9)
3.00009155...
...


          想起了高中的时候,在网上找casio fx 82es刷机教程,其中有一个就是“牛顿解方程”模式,一直觉得这个名字好霸气(毕竟和牛顿扯上关系了)。
        牛顿解方程很好用,比如求一个方程(一元)的解,直接吧方程输到计算器就成,十分好用(对于我这种粗心大意的又懒的人,简直不能更好)。一直不知道为什 么这个刷机模式为什么叫“牛顿解方程”,记得当时余意老师讲过一种迭代求什么根的东西,但是我觉得好白痴,明明按计算器更快,还要人算。。。没有计算器简 直什么都不想干。那次数学竞赛和生物竞赛冲突了,我数学虽然差 ,但我是热心观众不能不凑热闹,但是生物也不能不去,我可是选修生物的。最后去了数学,因为余意骗我说可以带计算器。结果,考场就在我们学校,监考老师就 是余意,她第一句话就是”考试不能使用计算器“。。。没有希望的希望杯!
        没有计算器的数学考试我可以去死,宁可不写。2位以上的计算我都不太习惯思考,sin那三个总要想很久,所以从来是直接按计算器。那是按 计算器真是快,在15班的时候还一群人看谁刷的快。。。后来刷机的方法学的越来越多,可以刷出base-n进制转换,求方程组,求积分和导数(高中不教这 个所以也不怎么会用),矩阵向量统计什么的,还有一些很fancy的爆机方法,最牛逼的是卢wc的那个,可以让计算器瞬间无法开机,除非用起子打开壳子把 电池抠出来放一会。如此强大,以至于每次考数学前都要去欺负彭p,"乖点不然把你计算器刷死"。。。(这应该是赤裸裸的调戏。。)
        后来高考前把计算器换成了991,现在还在用,不用刷就有了所有82es  b版按百来个键才能刷出来的功能,省去了刷机的麻烦,也
没了少个那个乐趣

相关内容