我是靠谱客的博主 忐忑电脑,最近开发中收集的这篇文章主要介绍MIT 6.00.1X --Week 3,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

NEWTON-RAPHSON ROOT FINDING


  • General approximation algorithm to find roots of a
    polynomial in one variable

p(x)=anxn+an1xn1++a1x+a0

  • Want to find r such that p(r) = 0
  • Newton showed that if g is an approximation to the
    root, then
    gp(g)/p(g)
    is a better approximation; where p’ is derivative of p.
# Lecture 3.7, slide 3
# Newton-Raphson for square root
epsilon = 0.01
y = 24.0
guess = y/2.0
while abs(guess*guess - y) >= epsilon:
guess = guess - (((guess**2) - y)/(2*guess))
print(guess)
print('Square root of ' + str(y) + ' is about ' + str(guess))

# lecture 3.6, slide 2
# bisection search for square root
x = 12345
epsilon = 0.01
numGuesses = 0
low = 0.0
high = x
ans = (high + low)/2.0
while abs(ans**2 - x) >= epsilon:
print('low = ' + str(low) + ' high = ' + str(high) + ' ans = ' + str(ans))
numGuesses += 1
if ans**2 < x:
low = ans
else:
high = ans
ans = (high + low)/2.0
print('numGuesses = ' + str(numGuesses))
print(str(ans) + ' is close to square root of ' + str(x))

普通迭代

x = 25
epsilon = 0.01
step = 0.1
guess = 0.0
while guess <= x:
if abs(guess**2 -x) < epsilon:
break
else:
guess += step
if abs(guess**2 - x) >= epsilon:
print 'failed'
else:
print 'succeeded: ' + str(guess)

FLOATING POINT ACCURACY


浮点数的二进制表示与还原

先挖个坑。。。
参考《计算机专业导论之思维与系统》

最后

以上就是忐忑电脑为你收集整理的MIT 6.00.1X --Week 3的全部内容,希望文章能够帮你解决MIT 6.00.1X --Week 3所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部