역삼각함수란 삼각함수의 역함수를 의미하고,
역쌍곡선함수란 쌍곡선함수의 역함수를 의미한다.
수학에서 sin 함수의 역함수는 arcsin 으로 표기되는데,
Scala 언어에서는 scala.math.asin(Double) 메소드로 구현되어 있다.
/*
* Filename: testArcSine.scala
*
* Execute: scala -deprecation testArcSine.scala
*
* Or
*
* Compile: scalac -d. -deprecation testArcSine.scala
* Execute: scala -classpath . -deprecation testArcSine
*
* Date: 2013. 1. 1.
* Copyright (c) pkim _AT_ scripts.pe.kr
*/
import java.io._
object testArcSine {
def sin(x: Double) : Double = {
var y = scala.math.sin(x)
return y
}
def asin(x: Double) : Double = {
var y = scala.math.asin(x)
return y
}
def acos(x: Double) : Double = {
var y = scala.math.acos(x)
return y
}
def sinh(x: Double) : Double = {
var y = scala.math.sinh(x)
return y
}
def cosh(x: Double) : Double = {
var y = scala.math.cosh(x)
return y
}
def asinh(x: Double) : Double = {
var y = scala.math.log(x + scala.math.sqrt(x*x + 1))
return y
}
def acosh(x: Double) : Double = {
var y = scala.math.log(x + scala.math.sqrt(x*x - 1))
return y
}
def main(args: Array[String]) {
var x = -0.9
var y = asin(x)
printf("y = asin(%.1g) = %.9f\n", x, y)
printf("sin(y) = sin(%.9f) = %.1g\n", y, sin(y))
printf("\n")
x = 1.1
var u = acosh(x)
printf("u = acosh(%3.2g) = %.10f\n", x, u)
var v = asinh(x)
printf("v = asinh(%3.2g) = %.10f\n", x, v)
printf("cosh(u) = cosh(%.10f) = %3.2g\n", u, cosh(u))
printf("sinh(v) = sinh(%.10f) = %3.2g\n", v, sinh(v))
}
}
/*
Output:
y = asin(-0.9) = -1.119769515
sin(y) = sin(-1.119769515) = -0.9
u = acosh(1.1) = 0.4435682544
v = asinh(1.1) = 0.9503469298
cosh(u) = cosh(0.4435682544) = 1.1
sinh(v) = sinh(0.9503469298) = 1.1
*/
'프로그래밍 > Scala' 카테고리의 다른 글
Scala 언어로 평방근, 입방근, n제곱근 구하는 함수를 구현하고 테스트하기 (0) | 2013.01.12 |
---|---|
숫자 맞추기 게임 with Scala (0) | 2009.11.05 |
스트링 배열에서 스트링 찾기(find) with Scala (0) | 2009.04.22 |
스트링 배열 정렬(sorting)하기 with Scala (0) | 2009.04.18 |
대화형 모드의 진법(radix) 변환 예제 with Scala (0) | 2009.03.09 |