역삼각함수란 삼각함수의 역함수를 의미하고,
역쌍곡선함수란 쌍곡선함수의 역함수를 의미한다.
수학에서 sin 함수의 역함수는 arcsin 으로 표기되는데, Common Lisp 언어에서는 asin 함수로 이미 구현되어 있다. 마찬가지로 쌍곡선 함수 sihh, cosh 들의 역함수들도 각각 asinh, acosh 라는 이름으로 이미 구현되어 있다.
;; Filename: testArcSine.lsp
;;
;; Execute: clisp testArcSine.lsp
;; Or
;; Execute: ./testArcSine.lsp
;;
;; Date: 2013. 9. 12.
#|
def asinh(x):
y = math.log(x + math.sqrt(x*x + 1))
return y
def acosh(x):
y = math.log(x + math.sqrt(x*x - 1))
return y
|#
(format t "Using the type of float, ~%")
(setf x -0.9)
(setf y (asin x))
(format t " y = asin(~,1f) = ~,9f~%" x y)
(format t " sin(y) = sin(~,9f) = ~,1f~%" y (sin y))
(setf x 1.1)
(setf u (acosh x))
(setf v (asinh x))
(format t " u = acosh(~,1f) = ~,9f~%" x u)
(format t " v = asinh(~,1f) = ~,9f~%" x v)
(format t " cosh(u) = cosh(~,9f) = ~,1f~%" u (cosh u))
(format t " sinh(u) = sinh(~,9f) = ~,1f~%" v (sinh v))
(format t "~%")
(format t "Using the type of short-float, ~%")
(setf x -0.9S0)
(setf y (asin x))
(format t " y = asin(~f) = ~f~%" x y)
(format t " sin(y) = sin(~f) = ~f~%" y (sin y))
(setf x 1.1S0)
(setf u (acosh x))
(setf v (asinh x))
(format t " u = acosh(~f) = ~f~%" x u)
(format t " v = asinh(~f) = ~f~%" x v)
(format t " cosh(u) = cosh(~f) = ~f~%" u (cosh u))
(format t " sinh(u) = sinh(~f) = ~f~%" v (sinh v))
(format t "~%")
(format t "Using the type of double-float, ~%")
(setf x -0.9D0)
(setf y (asin x))
(format t " y = asin(~f) = ~f~%" x y)
(format t " sin(y) = sin(~f) = ~f~%" y (sin y))
(setf x 1.1D0)
(setf u (acosh x))
(setf v (asinh x))
(format t " u = acosh(~f) = ~f~%" x u)
(format t " v = asinh(~f) = ~f~%" x v)
(format t " cosh(u) = cosh(~f) = ~f~%" u (cosh u))
(format t " sinh(u) = sinh(~f) = ~f~%" v (sinh v))
(format t "~%")
(format t "Using the type of long-float, ~%")
(setf x -0.9L0)
(setf y (asin x))
(format t " y = asin(~f) = ~f~%" x y)
(format t " sin(y) = sin(~f) = ~f~%" y (sin y))
(setf x 1.1L0)
(setf u (acosh x))
(setf v (asinh x))
(format t " u = acosh(~f) = ~f~%" x u)
(format t " v = asinh(~f) = ~f~%" x v)
(format t " cosh(u) = cosh(~f) = ~f~%" u (cosh u))
(format t " sinh(u) = sinh(~f) = ~f~%" v (sinh v))
(format t "~%")
#|
Output:
Using the type of float,
y = asin(-0.9) = -1.119769600
sin(y) = sin(-1.119769600) = -0.9
u = acosh(1.1) = 0.443568350
v = asinh(1.1) = 0.950346950
cosh(u) = cosh(0.443568350) = 1.1
sinh(u) = sinh(0.950346950) = 1.1
Using the type of short-float,
y = asin(-0.9) = -1.11978
sin(y) = sin(-1.11978) = -0.9
u = acosh(1.1) = 0.443573
v = asinh(1.1) = 0.95035
cosh(u) = cosh(0.443573) = 1.1
sinh(u) = sinh(0.95035) = 1.1
Using the type of double-float,
y = asin(-0.9) = -1.1197695149986342
sin(y) = sin(-1.1197695149986342) = -0.9
u = acosh(1.1) = 0.4435682543851155
v = asinh(1.1) = 0.9503469298211343
cosh(u) = cosh(0.4435682543851155) = 1.1
sinh(u) = sinh(0.9503469298211343) = 1.1
Using the type of long-float,
y = asin(-0.9) = -1.1197695149986341867
sin(y) = sin(-1.1197695149986341867) = -0.90000000000000000003
u = acosh(1.1) = 0.44356825438511518925
v = asinh(1.1) = 0.95034692982113425026
cosh(u) = cosh(0.44356825438511518925) = 1.1
sinh(u) = sinh(0.95034692982113425026) = 1.1
|#
'프로그래밍 > Common Lisp' 카테고리의 다른 글
Common Lisp 언어로 한 번의 floor 함수 호출로 몫과 나머지 구하기 (0) | 2013.09.15 |
---|---|
스트링 벡터에서 스트링 찾기(find) with Common Lisp (0) | 2013.09.12 |
감마함수(gamma function)의 값을 (유효수자 15자리 까지 정밀하게) 계산하는 Common Lisp 언어 소스 (0) | 2013.09.08 |
Common Lisp 언어로 복소수 계산하기 (0) | 2013.09.07 |
Common Lisp 를 이용한 간단한 수학식 계산하기 (0) | 2013.09.07 |