I am having some issue while writing symbolic differentiation in lisp. I am trying write derivative of sqrt (x) but when i use this variable inside code, it give me that x is not defined.
;----------------------------------------
; deriv sqrt
;----------------------------------------
(defun derivsqrt (expr var)
(smult (smult (sdiv 1 2)
(sqrt (second expr))) ; This line gives me error
(deriv (second expr) var)))
I am calling this function like:
((eq 'sqrt (first expr))
(derivsqrt expr var))
and I am testing it with: (deriv '(sqrt (* 3 x)) 'x)
Can somebody help?
(second expr)
is the list (* 3 x)
which is not a number, but the function sqrt
demands a number for its argument. Since you say you want to do symbolic differentiation, you probably should return a list with the symbol sqrt
in it, rather than calling the function.