Pascal Bourguignon <firstname.lastname@example.org> wrote:
| "sandeep patil" <email@example.com> writes:
| > can you tell me any function in ohms law & it related program.
| > who i will right program on it.
| Ohm's Law, for a resistor, is:
| U = R * I (voltage = resistance * intensity)
FYI, in standard English engineering notation/language,
the symbol for voltage is "V", not "U". And the symbol "I"
refers to "current", not "intensity". And although this
doesn't matter at all to correctness, the rule is usually
given with "R" last [for unknown-to-me historical reasons,
V = I * R (voltage = current * resistance)
| You can write a function in Common Lisp to solve this equation,
| known at least two of its variables:
| (defun resistor-ohm-law (&key u r i)
| (u (cond (r (list :i (/ u r)))
| (i (list :r (/ u i)))
| (t (list :|R(I)| (lambda (i) (/ u i))
| :|I(R)| (lambda (r) (/ u r)))))
Yes, this is one place where I really, really like CL's keywords!!
But I generally write this kind of thing as follows, which feels to
me to be more perspicuous [though admittedly slightly more redundant
and thus *slightly* less efficient -- a tradeoff I'm usually willing
(defun resistor-ohm-law (&key v r i)
((and v i r)
(error "May not specify all three parameters!"))
((and v r) (list :i (/ v r)))
((and v i) (list :r (/ v i)))
((and i r) (list :v (* i r)))
(error "Must specify at least two parameters!"))))
Rob Warnock <firstname.lastname@example.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607