第一次写这种类型的程序,精度控制也不知道对不对,见笑了:- (defun c:test( / a b c d step dir m x y)
- (setq a (getreal "输入a:"))
- (setq b (getreal "输入b:"))
- (setq c (getreal "输入c:"))
- (setq d (getreal "输入d:"))
- (setq step 10)
- (setq dir 1)
- (setq m t)
- (setq i 0 x -100)
- (while m
- (setq x (+ x (* i dir step)))
- (setq y (+ (* a (expt x 3)) (* b (expt x 2)) (* c x) d))
- (if (> (* y dir) 0)
- (progn
- (if (< step 0.00001) (setq m nil))
- (setq dir (* dir -1))
- (setq step (/ step 2.0))
- )
- )
- (setq i (1+ i))
- )
- (princ x)
- (princ)
- )
|