作者sjgau (sjgau)
看板Cad_Cae
标题一个比较精简的 费氏数列 LISP
时间Mon Nov 21 13:52:41 2005
; file: T0130.LSP
(defun f33 (no /)
(cond
((<= no 0) 0)
((= no 1) 1)
((= no 2) 1)
(T (+ (f33 (- no 2)) (f33 (- no 1))))
)
) ; end of f33()
; main() begin here
; for no= 2 to 30 do ...
(setq no 2)
(while (<= no 30)
(setq n1 (f33 (1- no)))
(setq n2 (f33 no))
(setq x1 (/ (float n2) (float n1)))
(princ (strcat "no= " (itoa no) ", x1= " (rtos x1 2 18) "\n")
)
(setq no (1+ no))
) ; end of while()
(princ) ; the last line of main()
; end of file
还需要改进的地方
一 模拟 printf("x1= %25.22lf\n", x1);
尚不完整
二 和期望值得比较
期望值= (sqrt(5.0) + 1.0)/(2.0)
三 比较的方法
绝对误差 和 相对误差的 user defined function
※ 引述《sjgau (sjgau)》之铭言:
: 破 一万人次纪念
: 可以到 我的 部落格 讨论 LISP 学习的问题
: ※ 引述《sjgau (sjgau)》之铭言:
: : (princ "hello, world!\n")
: : (princ)
: : 程式档案名称:hello.lsp
: : 内容只有以上的两行。
: : 要执行这个程式,很简单。
: : 在 AutoCAD 指令行下面,输入
: : (load "hello")
: : 即可正确执行。
: : 更多的内容,请参考我的 BLOG
: : http://myblog.pchome.com.tw/sjgau/
: : 参观次破 1,000 纪念
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.243.238.233