首页 > 其他分享 >sicp每日一题[2.9]

sicp每日一题[2.9]

时间:2024-09-14 10:51:37浏览次数:1  
标签:newline r2 get 每日 interval sicp width 2.9 intervals

Exercise 2.9

The width of an interval is half of the difference between its upper and lower bounds. The width is a measure of the uncertainty of the number specified by the interval. For some arithmetic operations the width of the result of combining two intervals is a function only of the widths of the argument intervals, whereas for others the width of the combination is not a function of the widths of the argument intervals. Show that the width of the sum (or difference) of two intervals is a function only of the widths of the intervals being added (or subtracted). Give examples to show that this is not true for multiplication or division.


这道题目没有任何难度,只要把原来的区间宽度和经过加减之后的区间宽度表示出来,它们的关系也就一目了然了。

; 计算区间的宽度
(define (get-width x)
  (/ (- (upper-bound x) (lower-bound x)) 2))


(define r1 (make-interval 6.12 7.48))
(define r2 (make-interval 4.465 4.935))

(display (get-width r1))
(newline)
(display (get-width r2))
(newline)
(display (get-width (add-interval r1 r2)))
(newline)
(display (get-width (sub-interval r1 r2)))
(newline)

; 执行结果
0.6800000000000002
0.23499999999999988
0.9149999999999991
0.915

根据执行结果可以看出,加减之后的区间宽度等于原来两个区间宽度之和。

标签:newline,r2,get,每日,interval,sicp,width,2.9,intervals
From: https://www.cnblogs.com/think2times/p/18413525

相关文章

  • SolidJS-每日小知识(9/13)
    知识介绍在div容器中并列两个SVG元素->对div容器设置display:"flex"使用d3创建散点图使用d3的scaleLinear函数创建x轴和y轴的比例尺对d3的svg元素增加tooltip提示对svg元素增加zoom功能使用d3在svg中画线对d3中某个元素的attr属性使用函数表达式return值代码分析2......
  • 【每日一题】LeetCode 2398.预算内的最多机器人数目(滑动窗口、数组、二分查找、前缀和
    【每日一题】LeetCode2398.预算内的最多机器人数目(滑动窗口、数组、二分查找、前缀和、堆(优先队列))题目描述给定两个整数数组chargeTimes和runningCosts,分别代表n个机器人的充电时间和运行成本。再给定一个整数budget,表示预算。我们需要计算在不超过预算的情况下,最......
  • sicp每日一题[2.8]
    Exercise2.8>UsingreasoninganalogoustoAlyssa's,describehowthedifferenceoftwointervalsmaybecomputed.Defineacorrespondingsubtractionprocedure,calledsub-interval.这道题目也比较简单,只要注意到区间之差的下界是被减区间的下界减去另一个区间的上......
  • sicp每日一题[2.7]
    2.7Alyssa’sprogramisincompletebecauseshehasnotspecifiedtheimplementationoftheintervalabstraction.Hereisadefinitionoftheintervalconstructor:(define(make-intervalab)(consab))Defineselectorsupper-boundandlower-boundtoco......
  • 【每日一题】LeetCode 2576.求出最多标记下标(贪心、数组、双指针、二分查找、排序)
    【每日一题】LeetCode2576.求出最多标记下标(贪心、数组、双指针、二分查找、排序)题目描述给定一个整数数组nums,数组下标从0开始。你需要执行以下操作,直到无法再执行为止:选择两个互不相同且未标记的下标i和j。满足条件2*nums[i]<=nums[j],则标记下标i和j。......
  • 【每日刷题】Day119
    【每日刷题】Day119......
  • SolidJS-每日小知识(9/12)
    知识介绍对SVG元素实现拖拽视图的功能代码分析对于SVG元素的viewBox属性(x,y,w,h),我们设置x,y作为信号量const[boxLocation,setboxLocation]=createSignal({x:0,y:0});添加拖拽所需的变量和事件letisDragging=false;letstartX:number;letst......
  • sicp每日一题[2.6]
    Exercise2.6Incaserepresentingpairsasprocedureswasn'tmind-bogglingenough,considerthat,inalanguagethatcanmanipulateprocedures,wecangetbywithoutnumbers(atleastinsofarasnonnegativeintegersareconcerned)byimplementing0a......
  • 每日OJ_牛客_合唱团(打家劫舍dp)
    目录牛客_合唱团(打家劫舍dp)解析代码1解析代码2牛客_合唱团(打家劫舍dp)合唱团__牛客网        有n个学生站成一排,每个学生有一个能力值,牛牛想从这n个学生中按照顺序选取k名学生,要求相邻两个学生的位置编号的差不超过d,使得这k个学生的能力值的乘积最大,......
  • SolidJS-每日小知识(9/11)
    知识介绍对指定SVG元素实现滚轮zoom代码分析1.对指定SVG元素实现滚轮zoom设置viewBox属性{x,y,w,h}以及缩放系数scale为信号量const[scale,setScale]=createSignal(1);//初始缩放比例const[boxLocation,setboxLocation]=createSignal({x:0,y:0});......