본문 바로가기

IT/Numerical analysis

Secant Method c언어로 구현하기 #include #include #define PI 3.1415926535897931#define e 2.71828 #define thshold 2 * pow(10,-4) double fx(double x){ return (7*sin(x) * pow(e,(-x)) -1);} void Secant_Method(double xl, double xu){ double a,b,fa,fb,p; double sol; int i=0; double eia=100; double eit; a = xl; b = xu; fa=fx(a); fb=fx(b); while(1) { p=b-fb*(b-a)/(fb-fa); eia = fabs((b-a)/b)*100; if(eia 더보기
False Position Method c언어로 구현하기 #include #include #define thshold 2 * pow(10,-4) double sinfx(double x){ return (x*x - sin(x));} void false_position(double xl, double xu){ int i; double q0, q1, q,p; double num = 40; double xr2; q0 = sinfx(xl); q1 = sinfx(xu); i = 1; p = xu - q1 * (xu - xl) / (q1 - q0); q = sinfx(p); double e0=100.0; printf("%d\t%lf\t%lf\t%lf\t%lf\n", i, xl,xu,p, e0); while(1) { p = xu - q1 * (xu - xl) / (q1 - .. 더보기
야코비(Jacobi) Method C언어로 구현하기 /* Jacobi Method */ #include #include #include #include int it=0;double **a;double *b;double *s;#define EPS 1e-5 // 최대 오차#define ITOR 500 // 최대 반복 횟수 int n; // 행렬의 갯수 FILE *fp; double** matrix_malloc(int n){ double **a; int i,j; a=(double **)malloc(n*sizeof(double)); for(i=0;i 더보기
Bisection Method C언어로 구현하기 /* written by kaspy (kaspyx@gmail.com)*/ 수치해석에서 나오는 해를 찾는 방법이다.수학에서 이분법(二分法, Bisection method)은 근이 반드시 존재하는 폐구간을 이분한 후, 이 중 근이 존재하는 하위 폐구간을 선택하는 것을 반복하여서 근을 찾는 알고리즘이다. 간단하고 견고하나, 상대적으로 느린 방식이다. 참고 위키http://ko.wikipedia.org/wiki/%EC%9D%B4%EB%B6%84%EB%B2%95_(%EC%88%98%ED%95%99) f(x) = x^2 * sin(x) 로 주어졌을때 #include #include #define PI 3.1415926535897931 #define thshold 2 * pow(10,-4) double sinfx(d.. 더보기
테일러(Taylor) 급수 C언어로 구하기 무한 급수 중에 테일러(Taylor) 급수라는 놈이 있는데, f(x)의 값은 f의 테일러 급수의 충분히많은 항들을 더해줌으로써 요구되는 정확도의 범위안에서 근사 시킬수 있다 대표적인 간단한 테일러 급수로는 를 들수 있겠다. 과연 n을 무한데로 보내면 e^x 와 숫자와 수렴할까? 아래 코딩을 통해 알아보자. x 를 -2.0 에서 2.0 까지 증가시키며 n을 1부터 5까지 증가시키며 원래 e^x 와의 오차를 비교하는 프로그램이다. #include #include // programmed by kaspyx#define e 2.71828 //e는 근사치로 상수로 정의double power(double x,int pdg) // x를인자로 받아 pdg 제곱하여 결과를 리턴{ double pow=1; if ( pdg.. 더보기