我应该测试这些Lisp程序,但太懒了。
- ;; supply two of the three arguments to get the third
- (defun OhmsLawPVR (P V R)
- (cond
- ((not P) (/ (* V V) R))
- ((not V) (sqrt (* P R)))
- ((not R) (/ (* V V) P))
- )
- )
- (defun OhmsLawPVI (P V I)
- (cond
- ((not P) (* V I))
- ((not V) (/ P I))
- ((not I) (/ P V))
- )
- )
- (defun OhmsLawVIR (V R I)
- (cond
- ((not V) (* R I))
- ((not R) (/ V I))
- ((not I) (/ V R))
- )
- )
- (defun OhmsLawPIR (P I R)
- (cond
- ((not P) (* (* I I) R))
- ((not R) (/ P (* I I)))
- ((not I) (sqrt (/ P R)))
- )
- )
- ;; solve for S given 2 of the remaining 3 variables
- ;; S = string "P" "V" "R" "I"
- ;; should have error checking
- (defun OhmsLaw? (S P V R I)
- (setq S (strcase S))
- (cond
- ((= S "P") ; return Power/Watts
- (cond
- ((not R) (* V I))
- ((not V) (* (* I I) R))
- ((not I) (/ (* V V) R))
- )
- )
- ((= S "V") ; return Volts/EMF
- (cond
- ((not P) (* R I))
- ((not R) (/ P I))
- ((not I) (sqrt (* P R)))
- )
- )
- ((= S "R") ; return Resistance/Ohms
- (cond
- ((not P) (/ V I))
- ((not I) (/ (* V V) P))
- ((not V) (/ P (* I I)))
- )
- )
- ((= S "I") ; return Inductance/Amps
- (cond
- ((not P) (/ V R))
- ((not R) (/ P V))
- ((not V) (sqrt (/ P R)))
- )
- )
- )
- )
|