역삼각함수란 삼각함수의 역함수를 의미하고,

역쌍곡선함수란 쌍곡선함수의 역함수를 의미한다.

수학에서 sin 함수의 역함수는 arcsin 으로 표기되는데, ErLang 언어에서는 asin 함수로 구현되어 있다.

OCaml 언어는 F#, Scala 언어 처럼 비순수 함수형 언어이다. (여기서 바순수라 함은 절차적 언어 처럼 for, while, break 등의 제어문 기능을 갖고 있어서 C 언어나 Java 언어 처럼 작성할 수 있다는 뜻이다.)

OCaml 언어로 작성된 소스에서는 각 명령 줄이 두 개의 세미콜론(;;)으로 끝나야 한다.

영문 위키피디아의 OCaml  프로그래밍 언어 설명: http://en.wikipedia.org/wiki/OCaml

OCaml 언어로 부동소수점수(float 타입, 이느 C 언어와 Java 언어의 double 타입에 해당)의 사칙 연산 기로가 +, -, *, / 가 아니라 각 연산지 뒤에 점(.)을 하나씩 추가한 +., -., *., /. 임에 주위 한다. 정수(int) 타입의 사칙 연산 기호는 +, -, *, / 를 그대로 사용한다. 그리고 float 타입과 int 타입을 섞어서 연산할 때는 반드시 타입을 통일시키는 작업을 해야 한다.

아래에서 샤프 기호(#)는 OCaml 의 프롬프트이다. 테스트는 진한 글자로 된 부분만 입력하면 된다.

명령프롬프트> ocaml
        Objective Caml version 3.12.1

# 3 + 1.2;;
Characters 4-7:
  3 + 1.2;;
      ^^^
Error: This expression has type float but an expression was expected of type
         int
# (float_of_int 3) + 1.2;;
Characters 0-16:
  (float_of_int 3) + 1.2;;
  ^^^^^^^^^^^^^^^^
Error: This expression has type float but an expression was expected of type
         int
# (float_of_int 3) +. 1.2;;
- : float = 4.2
# 3 + (int_of_float 1.2);;
- : int = 4

 

아래의 소스는 컴파일 없이 "ocaml 소스파일명" 으로 실행해도 되고, "ocamlc -o 실행파일명 소스파일명" 컴파일한 뒤 생성된 실행파일을 실행해도 된다.

컴파일하여 실행하는 경우 현재 최신 버전인 OCaml 4.00.1 은 "NTVDM CPU CS ......" 에러가 발생힌디.


OCaml 3.12.* 에서는 컴파일 하여 실행하더러도 아무 문제가 없다.

(윈도우 Vista, XP, 7 등에서 OCaml 3.12.1 은 설치되는 중에 시스템 환경변수 PATH 의 값을 삭제해 버리므로 주의를 요한다. PATH 의 값을 다른 곳에 저장해 두었다가 복원해야 함.)

 

(*
   Filename: testArcSine.ml
 
   Execute: ocaml testArcSine.ml

     Or
 
   Compile: ocamlc -o testArcSine testArcSine.ml
   Execute: ./testArcSine
 
     Or
 
   Compile: ocamlc -o testArcSine.exe testArcSine.ml
   Execute: testArcSine.exe
 
   Date: 2013. 1. 3.
   Copyright (c) pkim _AT_ scripts.pe.kr
*)


let asinh x = log(x +. sqrt(x *. x +. 1.0));;

let acosh x = log(x +. sqrt(x *. x -. 1.0));;

let x = -0.9;;
let y = asin(x);;

let _ = Printf.printf "y = asin(%g) = %.9f\n" x y;;
let _ = Printf.printf "sin(y) = sin(%.9f) = %g\n" y (sin y) ;;
let _ = Printf.printf "\n";;

let x = 1.1;;
let u = acosh(x);;
let _ = Printf.printf "u = acosh(%g) = %.10f\n" x u;;
let v = asinh(x);;
let _ = Printf.printf "v = asinh(%g) = %.10f\n" x v;;

let _ = Printf.printf "cosh(u) = cosh(%.10f) = %g\n" u (cosh u);;
let _ = Printf.printf "sinh(v) = sinh(%.10f) = %g\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
*)

 

 

Posted by Scripter
,

역삼각함수란 삼각함수의 역함수를 의미하고,

역쌍곡선함수란 쌍곡선함수의 역함수를 의미한다.

수학에서 sin 함수의 역함수는 arcsin 으로 표기되는데, ErLang 언어에서는 asin 함수로 구현되어 있다.

ErLang 언어는 Haskell 언어 처럼 순수 함수형 언어이다.

ErLang 언어로 프로그래밍할 때는 각 명령 줄 끝이 콤마(,)로 끝나는지, 마침표(.)로 끝나는지 신경을 단단히 써야 한다. 콤마로 끝나는 줄은 그 다음에 명령이 이어진다는 의미이고, 마침표로 끝나는 것은 그 블록이 (Ruby 언어나 Lua 언어의 end 처럼) 블럭이 끝남을 의미한다.

영문 위키피디아의 ErLang 프로그래밍 언어 설명: http://en.wikipedia.org/wiki/Erlang_(programming_language)

(참고. ErLang 언어는 대소 문자를 구분하며 타입에 동적인 언어이다. 그리고 변수는 대문자로 써야 한다.) 

아래의 소스는 컴파일 없이 erl 로 실행하면 되지만,. erlc 로 컴파일 할 경우 생성되는 실행 파일이 *.beam 파일이며 이것을 실행할 때도 조금은 복잡하게 실행해야 한다. (아래의 주석문 참조)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Filename: testArcSine.erl
%
% Compile: erlc testArcSine.erl
% Execute: erl -run testArcSine main -run init stop -noshell
%   Or
% Execute: erl
%        > c(testArcSine).
%        > testArcSine:main().
%
% Author: P. Kim pkim _AT_ scripts.pe.kr
%
% See: http://erlware.blogspot.kr/2010/10/console-applications-in-erlang.html
%
% Created by PKim pkim _AT_ scripts.pe.kr  2013. 1. 3.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

-module(testArcSine).
-author(pkim _AT_ scripts.pe.kr).
-export([main/0]).

asinh(X) -> math:log(X + math:sqrt(X*X + 1)).
acosh(X) -> math:log(X + math:sqrt(X*X - 1)).

main() ->
    X = -0.9,
    Y = math:asin(X),
    io:format("y = asin(~w) = ~.9f~n",  [X, Y]),
    io:format("sin(~.9f) = ~w~n",  [Y, math:sin(Y)]),
    io:format("~n"),

    X1 = 1.1,
    U = acosh(X1),
    io:format("u = acosh(~w) = ~.10f~n",  [X1, U]),
    V = asinh(X1),
    io:format("v = asinh(~w) = ~.10f~n",  [X1, V]),
    io:format("cosh(~.10f) = ~w~n",  [U, math:cosh(U)]),
    io:format("sinh(~.10f) = ~w~n",  [Y, math:cosh(Y)]).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Output:
% y = asin(-0.9) = -1.119769515
% sin(-1.119769515) = -0.9
%
% u = acosh(1.1) = 0.4435682544
% v = asinh(1.1) = 0.9503469298
% cosh(0.4435682544) = 1.1
% sinh(-1.1197695150) = 1.6952514438291528
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 

 

 

Posted by Scripter
,

역삼각함수란 삼각함수의 역함수를 의미하고,

역쌍곡선함수란 쌍곡선함수의 역함수를 의미한다.

수학에서 sin 함수의 역함수는 arcsin 으로 표기되는데, Haskell 언어에서는 asin 함수로 구현되어 있다.

또한 Haskell 언어에서는 쌍곡선함수 sinh, cosh 의 역함수들이 각각 asinh, acosh 라는 이름으로  이미 구현되어 있다. 그래서 비교를 위해 아래의 소스에 arcsinh, arccosh 라는 이름의 함수로 구현해 보았다.

영문 위키피디아의 GHC 설명: http://en.wikipedia.org/wiki/Glasgow_Haskell_Compiler

(참고. Haskell 언어는 대소 문자를 구분하며 타입에 엄격한 언어이다. ) 

아래의 소스는 Glasgow Haskell Compiler ghc 로 컴파일되는 소스이다.

 

{-
   Filename: testArcSine.hs
 
   Compile: ghc testArcSine.hs
   Execute: ./testArcSine
 
   Date: 2013. 1. 3.
   Copyright (c) pkim _AT_ scripts.pe.kr
-}

module Main where

import System.Environment
import Text.Printf

arcsinh :: (RealFloat a) => a -> a
arcsinh x = w where
                      w = log (x + sqrt (x*x + 1))

arccosh :: (RealFloat a) => a -> a
arccosh x = w where
                      w = log (x + sqrt (x*x - 1))


main :: IO ()       
main = do
    let x = -0.9 :: Double
    let y = asin x
   
    printf "y = asin(%f) = %.9f\n" x y
    printf "sin(y) = sin(%.9f) = %f\n" y (sin y)
    printf "\n"
   
    let x =1.1 :: Double
    let u = acosh x
    printf "u = acosh(%.1f) = %.10f\n" x u
    let v = asinh x
    printf "v = asinh(%.1f) = %.10f\n" x v
   
    printf "cosh(u) = cosh(%.10f) = %3.1g\n" u (cosh u)
    printf "sinh(v) = sinh(%.10f) = %3.1g\n" v (sinh v)
    printf "\n"

    printf "arccosh(%.1f) = %.10f\n" x (arccosh x)
    printf "arcsinh(%.1f) = %.10f\n" x (arcsinh x)


{-
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

arccosh(1.1) = 0.4435682544
arcsinh(1.1) = 0.9503469298
-}

 

 

Posted by Scripter
,

역삼각함수란 삼각함수의 역함수를 의미하고,

역쌍곡선함수란 쌍곡선함수의 역함수를 의미한다.

수학에서 sin 함수의 역함수는 arcsin 으로 표기되는데,

FreePascal 언어에서는 asin 함수로 구현되어 있다.

FreePascal 은 http://www.freepascal.org 에서 구할 수  있다.

아래의 소스는 FreePascal 의 (명령줄 컴파일 명령) fpc 로 컴파일되는 소스이다.

 

참고 1. FreePascal 은 이전(MS-DOS 시절)에 많이 쓰였던 Turbo Pascal 과 유사하며, Turbo Pascal을 발전시킨 것이라고 보변 된다. 아래는 Wikipedia 에서 적어 놓은 FreePascal 의 설명이다.

---------------------------------------------------

Free Pascal Compiler (FPC for short, and formerly known as FPK Pascal) is a free Pascal and Object Pascal compiler.

In addition to its own Object Pascal dialect, Free Pascal supports, to varying degrees, the dialects of several other compilers, including those of Turbo Pascal, Delphi, and some historical Macintosh compilers. The dialect is selected on a per-unit (module) basis, and more than one dialect can be used to produce a single program.

---------------------------------------------------

 

참고 2.  FreePascal 은 대소 문자 구분을 하지 않는다.

참고 3. uses 블럭에 sysutilsv 를 추가 한 것은 부동소수점수를 출력할시 작당한 반올림을 하여 출력하기 우함이다.

참고 4. 자연로그 함수로 다른 프로그램 언어에서는 보통 log 또는 Log 라는 이름으로 구현되어 있지만, FreePascal 에서는 ln 이라는 이름으로 구현되어 있다.

참고 5.  쌍곡선함수 sinh, cosh 의 역함수들이 각각 arsinh, arcosh 라는 이름으로  FreePascal 에 이미 구현되어 있지만, 비교를 위해 아래의 소스에 asinh, acosh 라는 이름의 함수로 구현해 놓았다. (문자 r 이 있고 없음의 차이)

 

(*
 * =============================================================
 * Filename: testArcSine.pas
 *
 *    This source should be compiled by using FreePascal,
 *    which can be downloaded from http://www.freebasic.net
 *
 *    See: http://www.freepascal.org/docs-html/rtl/sysutils/format.html
 *            for formatted strings.
 *
 * Compile: fpc testArcSine.pas
 * Execute: testArcSine
 *
 * Date: 2013. 1. 2.
 * Copyright (c) pkim _AT_ scripts.pe.kr
 * =============================================================
 *)

program CalculateArcSine;

uses 
    sysutils,   (* for format *)
    math;

var
     x : real;
     y : real;
     u : real;
     v : real;

function asinh(x : real) : real;
var
     y : real;
begin
     y := ln(x + sqrt(x*x + 1));
     asinh := y;
end;

function acosh(x : real) : real;
var
     y : real;
begin
     y := ln(x + sqrt(x*x - 1));
     acosh := y;
end;


begin
        x := -0.9;
        y := arcsin(x);
        Writeln( Format('y = asin(%.1f) = %.10f', [x, y]) );
        Writeln( Format('sin(y) = sin(%.9f) = %.1f', [y, sin(y)]) );
        Writeln();
       
        x := 1.1;
        u := arcosh(x);
        Writeln( Format('u = acosh(%.1f) = %.10f', [x, u]) );
       
        v := arsinh(x);
        Writeln( Format('v = asinh(%.1f) = %.10f', [x, v]) );

        Writeln( Format('cosh(u) = cosh(%.10f) = %.1f', [u, cosh(u)]) );
        Writeln( Format('sinh(v) = sinh(%.10f) = %.1f', [v, sinh(v)]) );
        Writeln;

        Writeln( Format('acosh(cosh(u)) = acosh(%.1f) = %.10f', [cosh(u), acosh(cosh(u))]) );
        Writeln( Format('asinh(sinh(v)) = asinh(%.1f) = %.10f', [sinh(v), asinh(sinh(v))]) );

end.


(*
Output:
y = asin(-0.9) = -1.1197695150
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

acosh(cosh(u)) = acosh(1.1) = 0.4435682544
asinh(sinh(v)) = asinh(1.1) = 0.9503469298

----------------
Unformatted output:
y = asin(-9.00000000000000E-001) = -1.11976951499863E+000
sin(y) = sin(-1.11976951499863E+000) = -9.0000000000000000E-0001

*)

 

 

 

Posted by Scripter
,

역삼각함수란 삼각함수의 역함수를 의미하고,

역쌍곡선함수란 쌍곡선함수의 역함수를 의미한다.

수학에서 sin 함수의 역함수는 arcsin 으로 표기되는데,

FreeBASIC 언어에서는 asin 함수로 구현되어 있다.

아래의 소스는 FreeBASIC 의 (명령줄 컴파일 명령) fbc 로 컴파일되는 소스이다.

참고 1. FreeBASIC 은 이전(MS-DOS 시절)에 쓰던 Quick BASIC 과 유사하며, Quick BASIC을 발전시킨 것이라고 보변 된다. 아래는 Wikipedia 에서 적어 놓은 FreeBASIC 의 설명이다.

---------------------------------------------------

FreeBASIC is a free/open source (GPL), 32-bit BASIC compiler[2] for Microsoft Windows, protected-mode DOS (DOS extender), Linux, FreeBSD and Xbox.

---------------------------------------------------

 

참고 2.  Double 타입의 부동소수점수를 원하는 위치에서 적당히 반올림하여 출력하기 위해서는 Format 또는 Format$ 함수를 써야 하는데, 이를 위해서는 FreeBASIC 언어에서는 소스에

#include "string.bi"

를 추가해야 한다.

(참고로, FreeBASIC 언어에서는 Print Using 과 "#.#########" 포맷을 이용해서 Double 타입을 출력하면, 근사값이라는 의미로 수치 앞에 퍼센트 기호(%)가 붙는다.)

 

참고 3.  제곱근을 구하기 위해 C, Java, Ruby, Python 언어에서는 sqrt 함수를 사용하고, Visual BASIC, C# 언어에서는 Sqrt 함수를 사용하지만, FreeVASIC 언어에서는 Quick BASIC 언어에서 처럼 Sqr 로 구현되어 있다. (Sqrt 가 아니라 마지막 분자 t 가 빠진 Sqr 임에 주의한다.)

 

참고 4.  FreeBASIC 언어에는 쌍곡선 함수가 구현되어 있지 않아 아래의 소스에 FreeBASIC 지수함수 Exp 를 이용하여 쌍곡ㅅ선 함수  sinh 함수와 cosh 함수를 구현헤 놓았다. 

 

REM =============================================================
REM Filename: testArcSine.bas
REM
REM    This source should be compiled by using FreeBASIC,
REM    which can be downloaded from http://www.freebasic.net
REM
REM Compile: fbc testArcSine.bas
REM Execute: testArcSine
REM
REM Date: 2013. 1. 2.
REM Copyright (c) pkim _AT_ scripts.pe.kr
REM =============================================================

#include "string.bi"

Function asinh(x As Double) As Double
        Dim y As Double = log(x + Sqr(x*x + 1))
        return y
End Function

Function cosh(x As Double) As Double
        Dim y As Double = (Exp(x) + Exp(-x))/2.0
        return y
End Function

Function sinh(x As Double) As Double
        Dim y As Double = (Exp(x) - Exp(-x))/2.0
        return y
End Function

Function acosh(x As Double) As Double
        Dim y As Double = log(x + Sqr(x*x - 1))
        return y
End Function


Sub Main()
        Dim x As Double = -0.9
        Dim y As Double = asin(x)
        ' Print Using "y = asin(" & x & ") = #"; y
        ' Print Using "y = asin(" & x & ") = #.#########"; y
        Print "y = asin(" & x & ") = "& Format$(y, "0.#########")
        ' Print "sin(y) = sin(" & y & ") = " & sin(y)
        ' Print Using "sin(y) = sin(#.########) = #"; y, sin(y)
        Print "sin(y) = sin(" & Format$(y, "0.#########") & ") = " & sin(y)
        Print

        x = 1.1
        Dim u As Double = acosh(x)
        ' Print "u = acosh(" & x & ") = " & u
        Print "u = acosh(" & x & ") = " & Format$(u, "0.#########")

        Dim v As Double = asinh(x)
        ' Print "v = asinh(" & x & ") = " & v
        Print "v = asinh(" & x & ") = " &  Format$(v, "0.##########")

        ' Print "cosh(u) = cosh(" & u & ") = " & Cosh(u)
        ' Print "sinh(v) = sinh(" & v & ") = " & Sinh(v)
        Print "cosh(u) = cosh(" & Format$(u, "0.#########") & ") = " & Cosh(u)
        Print "sinh(v) = sinh(" & Format$(v, "0.#########") & ") = " & Sinh(v)
           
        ' Print Format$(1.23, "#.#")
End Sub


Main()

' ---------------------------
' 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
' ---------------------------

 

 

 

Posted by Scripter
,

역삼각함수란 삼각함수의 역함수를 의미하고,

역쌍곡선함수란 쌍곡선함수의 역함수를 의미한다.

수학에서 sin 함수의 역함수는 arcsin 으로 표기되는데,

Groovy 언어에서는 Java 의  java.lang.Math.asin(double) 메소드f를 사용한다.

/*
 * Filename: testArcSine.groovy
 *
 * Execute: goovy  testArcSine.groovy
 *
 * Date: 2013. 1. 2.
 * Copyright (c) pkim _AT_ scripts.pe.kr
 */

def sin(double x)  {
            double y = Math.sin(x)
            return y
}

def double asin(double x) {
            double y = Math.asin(x)
            return y
}

def sinh(double x) {
            double y = Math.sinh(x)
            return y
}

def cosh(double x) {
            double y = Math.cosh(x)
            return y
}

def asinh(double x) {
            double y = Math.log(x + Math.sqrt(x*x + 1))
            return y
}

def acosh(double x) {
            double y = Math.log(x + Math.sqrt(x*x - 1))
            return y
}

def x = -0.9
def 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
def u = acosh(x)
printf("u = acosh(%3.2g) = %.10f\n", x,  u)

def 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
*/

 

 

 

Posted by Scripter
,

역삼각함수란 삼각함수의 역함수를 의미하고,

역쌍곡선함수란 쌍곡선함수의 역함수를 의미한다.

수학에서 sin 함수의 역함수는 arcsin 으로 표기되는데,

F# 언어에서는 .NET 의 System.Math.Asin(double) 함수를 사용한다.

(*
 * Filename: testArcSine.fs
 *
 * Compile: fsc testArcSine.fs
 * Execute: testArcSine
 *
 * Date: 2013. 1. 2.
 * Copyright (c) pkim _AT_ scripts.pe.kr
 *)

#light

let sin(x: double) : double =
            System.Math.Sin(x)

let asin(x: double) : double =
            System.Math.Asin(x)

let sinh(x: double) : double =
            System.Math.Sinh(x)

let cosh(x: double) : double =
            System.Math.Cosh(x)

let asinh(x: double) : double =
            System.Math.Log(x + sqrt(x*x + 1.0))

let acosh(x: double) : double =
            System.Math.Log(x + sqrt(x*x - 1.0))


let mutable x = -0.9
let mutable y = asin(x)
printfn "y = asin(%.1g) = %.9f" x  y
printfn "sin(y) = sin(%.9f) = %.1g" y (sin y)
printfn ""

x <- 1.1
let mutable u = acosh(x)
printfn "u = acosh(%3.2g) = %.10f" x u

let mutable v = asinh(x)
printfn "v = asinh(%3.2g) = %.10f" x  v

printfn "cosh(u) = cosh(%.10f) = %3.2g" u (cosh u)
printfn "sinh(v) = sinh(%.10f) = %3.2g" 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
*)

 

 

 

Posted by Scripter
,

역삼각함수란 삼각함수의 역함수를 의미하고,

역쌍곡선함수란 쌍곡선함수의 역함수를 의미한다.

수학에서 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
*/

 

 

 

Posted by Scripter
,

역삼각함수란 삼각함수의 역함수를 의미하고,

역쌍곡선함수란 쌍곡선함수의 역함수를 의미한다.

수학에서 sin 함수의 역함수는 arcsin 으로 표기되는데,

Go 언어에서는 math.Asin() 함수로 구현되어 있다.

/*
 * Filename: testArcSine.go
 *
 * Execute: go run testArcSine.go
 *
 *  Or
 *
 * Compile: go build testArcSine.go
 * Execute: testArcSine
 *
 * Date: 2013. 1. 1.
 * Copyright (c) pkim _AT_ scripts.pe.kr
 */
 
package main

import (
    "fmt"
    "math"
)

func asinh(x float64) float64 {
    y := math.Log(x + math.Sqrt(x*x + 1))
    return y
}

func acosh(x float64) float64 {
    y := math.Log(x + math.Sqrt(x*x - 1))
    return y
}

func main() {
 
    x := -0.9
    y := math.Asin(x)
    fmt.Printf("y = asin(%g) = %.9f\n", x, y)
    fmt.Printf("sin(y) = sin(%.9f) = %g\n", y, math.Sin(y))
    fmt.Printf("\n")

    x = 1.1
    u := acosh(x)
    fmt.Printf("u = acosh(%g) = %.10f\n", x, u)
 
    v := asinh(x)
    fmt.Printf("v = asinh(%g) = %.10f\n", x, v)
 
    fmt.Printf("cosh(u) = cosh(%.10f) = %g\n", u, math.Cosh(u))
    fmt.Printf("sinh(v) = sinh(%.10f) = %g\n", v, math.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
*/

 

 

 

Posted by Scripter
,

역삼각함수란 삼각함수의 역함수를 의미하고,

역쌍곡선함수란 쌍곡선함수의 역함수를 의미한다.

수학에서 sin 함수의 역함수는 arcsin 으로 표기되는데,

Lua 언어에서는 math.asin() 함수로 구현되어 있다.

 

-- Filename: testArcSine.lua
--
-- Execute: lua testArcSine.lua
--
-- Date: 2013. 1. 1.
-- Copyright (c) pkim _AT_ scripts.pe.kr

function sin(x)
    local y = math.sin(x)
    return y
end

function asin(x)
    local y = math.asin(x)
    return y
end

function sinh(x)
    local y = math.sinh(x)
    return y
end

function cosh(x)
    local y = math.cosh(x)
    return y
end

function asinh(x)
    local y = math.log(x + math.sqrt(x*x + 1))
    return y
end

function acosh(x)
    local y = math.log(x + math.sqrt(x*x - 1))
    return y
end


x = -0.9
y = asin(x)
print(string.format("y = asin(%g) = %.9f", x, y))
print(string.format("sin(y) = sin(%.9f) = %g", y, sin(y)))
print()

x = 1.1
u = acosh(x)
print(string.format("u = acosh(%g) = %.10f" , x, u))

v = asinh(x)
print(string.format("v = asinh(%g) = %.10f", x, v))

print(string.format("cosh(u) = cosh(%.10f) = %g", u, cosh(u)))
print(string.format("sinh(v) = sinh(%.10f) = %g", v, sinh(v)))

--[[
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
--]]

 

 

Posted by Scripter
,