本帖最后由 muwind 于 2021-9-21 22:38 编辑
;N阶矩阵
 - (defun tt (n / x m lst1 lst2 lst3)
- (if (> n 1)
- (progn
- (setq x 0
- lst1 '()
- lst3 '()
- )
- (while (< x n)
- (setq lst1 (cons (strcat "x" (vl-princ-to-string x)) lst1)
- x (1+ x))
- )
- (while (> x 0)
- (setq lst2 '()
- x (- x 1))
- (foreach m lst1
- (if (= m (strcat "x" (vl-princ-to-string x)))
- (setq lst2 (cons 1.0 lst2))
- (setq lst2 (cons 0.0 lst2))
- )
- )
- (setq lst3 ( cons lst2 lst3))
- )
- )
- )
- lst3
- )
以上是以前仿照(XD::Mat:Identity)写的一个任一N阶单位矩阵的 ,
(defun tt (n / x m lst1 lst2 lst3)
(if (> n 1)
(progn
(setq x 0
lst1 '()
lst3 '()
)
(while (< x n)
(setq lst1 (cons (strcat "x" (vl-princ-to-string x)) lst1)
x (1+ x))
)
(while (> x 0)
(setq lst2 '()
x (- x 1))
(mapcar
'(lambda(m)
(if (= m (strcat "x" (vl-princ-to-string x)))
(setq lst2 (cons 1.0 lst2))
(setq lst2 (cons 0.0 lst2))
)
) lst1
)
(setq lst3 ( cons lst2 lst3))
)
)
)
lst3
)
|