PLT[球拍/方案] 复利 +累加器 - 如何
我又在摆弄一项(应该很容易)的任务。
复利...(公式已知) 方案...(一年内一切都完美无缺)
问题:需要累加器... 我的程序必须能够记住前一个计算的结果,并将其作为下一个计算的蓝图。
我的问题来了:如何在没有列表的情况下设置accu过程....? 还是我现在就错了,我必须使用它们?
不知何故,我将不得不一次又一次地调用递归过程......
提前非常感谢, 诚挚的, Andreas_P
Andreas_P
I'm fiddling another time with a (should be easy) task.
compound interest... (formula is known)
Scheme... (For one single years everything works flawlessy)
Problem: Accumulator needed...
My program has to be able to remember the result of the former calculation and put it as a blueprint for the next one following.
Here comes my question: How to setup accu-procedures without lists....?
Or am I deadly wrong for now, and I must use them?
Somehow I'll have to call the recursive procedure again and again...
Many thanks in advance,
sincerely, Andreas_P
Andreas_P
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
读你的问题让我有点头晕。我有很多答案给你,但我感觉你不太确定你的问题是什么。
我给你的真正建议是如何设计程序的慷慨帮助。具体来说,您需要从第一步开始,决定您的程序接收和生成什么,并编写一行描述如何将输入映射到输出。
一如既往,对任何冒犯表示歉意。
Reading your question makes me a bit dizzy. I have a bunch of answers for you, but I get the sense that you're not quite sure what your question is.
My real advice for you is a generous helping of How To Design Programs. Specifically, you need to start at step one, and decide what your program takes in and produces, and write a one-line description of how the inputs are mapped to the outputs.
As always, apologies for any offense given.
您的意思是:
其中
pv
的值被周期末尾的值替换,并且每次递归周期数减少 1。SICP 很好地介绍了如何构造递归 ---值得一读。
Do you mean something like:
where the value of
pv
is replaced by the value at the end of the period, and the number of periods is reduced by one each recursion.SICP has good coverage of how to structure recursion --- it's worth a read.
非常感谢您的友好答复。
;;[没有真正的 DBC!]
;;合同:复利:号码号码号码->数量
;;目的:该函数必须创建一个“复利”计算方法,
;;当再次递归调用复利函数 x 次时。
;;示例:(复利 1000 1.05 360) // 应产生 1050
(定义 (复利 资本 利率 利息-时间)
(条件;
[(利息时间 >= 3600) 资本];
[其他;
(*利率(复利资本利率(-利息-时间360)))];
);
);
(复利 2000 1.05 360) 2100 0.1);
(check-within (复利 2000 1.05 720) 2205 0.01);
(check-within (复利 2000 1.05 1080) 2315.25 0.001);
(check-within (复利 2000 1.05 1440) 2431.0125 0.0001);
(复利 2000 1.05 1800) 2552.563125 0.00001);
(检查内(复利2000 1.05 2160) 2680.19128125 0.000001);
(检查内(复利2000 1.05 2540) 2814.20084531 0.0000001);
(检查内(复利2000 1.05 2900) 2954.91088758 0.000000001);
;(复利 2000 1.05 3260)
;(复利 2000 1.05 3600)
起初你是对的,我走错了路……关于累加器与否……
然后一位同学向我解释了原因,这就是结果。
嗯,[第一位评论者]:是的,它看起来非常相似,但因为它是 SICP,所以
计划用于 6.001 MIT,由于 DrRacket 中没有安装 SICP 校正模块,我无法真正使用它。
好吧[第二位评论者]:可能你是对的,我应该更详细地介绍一下
阅读更多关于我们教师中的“记忆功能”的内容。
最后但并非最不重要的一点是,感谢您的回答,我现在感觉(在某种程度上)受到启发来解决并关闭这个“线程”。
祝你有美好的一天......[极客们]
安德烈亚斯_P
Many thanks for your kind answers.
;;[No real DBC!]
;;CONTRACT: compound-interest: number number number -> number
;;PURPOSE: This function has to create a "compound interest" calculating method,
;; when recursively calling the compound interest function up to x times again.
;;EXAMPLE: (compound-interest 1000 1.05 360) //Should produce 1050
(define (compound-interest capital interest-rate interest-time)
(cond;
[(interest-time >= 3600) capital];
[else;
(* interest-rate (compound-interest capital interest-rate (- interest-time 360)))];
);
);
(check-within (compound-interest 2000 1.05 360) 2100 0.1);
(check-within (compound-interest 2000 1.05 720) 2205 0.01);
(check-within (compound-interest 2000 1.05 1080) 2315.25 0.001);
(check-within (compound-interest 2000 1.05 1440) 2431.0125 0.0001);
(check-within (compound-interest 2000 1.05 1800) 2552.563125 0.00001);
(check-within (compound-interest 2000 1.05 2160) 2680.19128125 0.000001);
(check-within (compound-interest 2000 1.05 2540) 2814.20084531 0.0000001);
(check-within (compound-interest 2000 1.05 2900) 2954.91088758 0.000000001);
;(compound-interest 2000 1.05 3260)
;(compound-interest 2000 1.05 3600)
At first you're correct I was on the wrong track... concerning accumulators or not...
then a fellow student explained me why and here is the result.
Well, [first commenter]: Yes it looks very similar, but because of it is SICP which was
planned for 6.001 MIT I couldn't make real use of, due to not having SICP correction module installed within DrRacket.
Well [second commenter]: probably you're right and I should go more into detail and
read some more about "memory functions" within our faculty.
Last but not least, Thank you for your both answers and I for now feel be (somewhat) enlightened to solve and close this "thread".
Have a nice day... [geek folks]
Andreas_P