2007/07/12 23:36

Taylor Sin(x)

Sin 을 처리하는 함수를 유사하게 만들어봅니다.

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ruru.Math
{
    public class Sin
    {
        public static double GetSin(double x)
        {
            double sum = 0.0;
            double r = 1.0;

            for (int i = 1; i < 13; i++)
            {
                r *= x / (1.0 * i);

                switch (i % 4)
                {
                    case 1: sum += r; break; // 1
                    case 3: sum += (-1) * r; break; // -1
                    case 2:
                    case 4: break; // 0
                }
            }
            return sum;
        }

        public static void PrintSin()
        {
            for (int i = 0; i < 180; i++)
                Console.WriteLine("Sin({0}) = {1}", i, GetSin(System.Math.PI*i/180.0));
        }
    }
}


 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ruru.Math
{
    class SinMain
    {
        static void Main(string[] args)
        {
            Sin.PrintSin();
        }
    }
}


크리에이티브 커먼즈 라이선스
Creative Commons License

'.NET > C#' 카테고리의 다른 글

C# 개미퀴즈 프로그램  (2) 2007/07/16
C#으로 짜본 야구게임  (0) 2007/07/16
4의배수 크기 마방진 알고리즘  (1) 2007/07/13
Taylor Sin(x)  (0) 2007/07/12
Taylor Series - Exp(x) 구현  (0) 2007/07/12
.NET에서 UnixTimestamp의 구현  (0) 2007/05/29
올블로그추천버튼 블코추천버튼 블로그뉴스추천버튼 믹시추천버튼 한RSS추가버튼 구글리더기추천버튼


이 포스팅이 도움이 되었다면 구글에서 관련 정보를 찾아 보세요 ^^


Trackback 0 Comment 0

Trackback : http://i-ruru.com/trackback/104 관련글 쓰기