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

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

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