문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top