/**********************************/

/*      Numerical Analysis Homework #2     */

/*      Department of Computer Science     */

/*      2003721181, Lee Seong woo          */

/**********************************/

#include <stdio.h>

#include <math.h>


#define CAPACITY 10


double func(double p);


int main(void)

{

        double p[CAPACITY];

        int i = 1;

        double tolerance = 0.0005;   // Tolerance - 오차 한계 값

        p[0] = 1.0; p[1] = 2.0;


        printf("-------------------------------------n");

        printf("n            pn              f(pn)   n");

        printf("-------------------------------------n");


        // p[i] 값과값 차이의 절대값이 Tolerance보다 작을 때 프로그램 종료

        while(fabs(p[i] - p[i - 1]) >= tolerance)

        {

                i++;

                p[i] = p[i-1] - (func(p[i-1]) * (p[i-1] - p[i-2])) / (func(p[i-1]) - func(p[i-2]));

                printf("%dt%.10ft%.10fn", i, p[i], func(p[i]));

        }

        printf("-------------------------------------n");


        return 0;

}


// 해를 구하기 위한 함수

double func(double p)

{

        return pow(p, 3) + 4 * pow(p, 2) - 10;

}


----
2007/09/20 - [놀이] - [과제] Numerical Analysis - C로 구현한 Bisection Method

+ Recent posts