수치해석 선형 보간법 newton법 secant법 c코딩
- 최초 등록일
- 2005.01.20
- 최종 저작일
- 2005.01
- 3페이지/ 한컴오피스
- 가격 1,000원
소개글
실행 소스
#include
#include
#define MAX_I 100
double x1, x2, x3, x3_old, f1, f2, f3, m, error;
int count;
double poly_f(double x);
double der_poly_f(double x);
void main(void)
{
//선형보간법
x1=-0.5;
x2=1.5;
int count;
for(count = 0; count < MAX_I; count++) {
f1 = poly_f(x1);
f2 = poly_f(x2);
m = (f2 - f1)/(x2 - x1);
x3_old = x3;
x3 = x2 - f2/m;
f3 = poly_f(x3);
if(f1*f3 > 0) {
x1 = x3;
f1 = f3;
}
else {
x2 = x3;
f2 = f3;
}
if(count != 0) {
error = (x3 - x3_old)/x3;
if(error<0)error=error*(-1);
if( error < 0.001 )
break;
}
}
printf("\n선형보간법");
printf("\n횟수 : %d", count);
printf("\n근 : %g", x3);
printf("\n오차백분율 : %g\n\n", 100*error);
//NEWTON법
x1=-0.5;
x2=1.5;
count=0;
x3=0;
for(count = 0; count < MAX_I; count++) {
f1 = poly_f(x1);
f2 = poly_f(x2);
x3_old = x3;
x3 = x2 - (x2 - x1)/(f2 - f1)*f2;
x1 = x2;
컴파일 실행환경
코딩한 것 입니다.
c언어로 코딩및 결과입니다.
결과는 볼수 있게 작성해였습니다.
한글 파일로 작성하였으니 c로 복사해 실행해 보세요.
본문내용
실행 소스
#include <stdio.h>
#include <math.h>
#define MAX_I 100
double x1, x2, x3, x3_old, f1, f2, f3, m, error;
int count;
double poly_f(double x);
double der_poly_f(double x);
void main(void)
{
//선형보간법
x1=-0.5;
x2=1.5;
int count;
for(count = 0; count < MAX_I; count++) {
f1 = poly_f(x1);
f2 = poly_f(x2);
m = (f2 - f1)/(x2 - x1);
x3_old = x3;
x3 = x2 - f2/m;
f3 = poly_f(x3);
if(f1*f3 > 0) {
x1 = x3;
f1 = f3;
}
else {
x2 = x3;
f2 = f3;
}
if(count != 0) {
error = (x3 - x3_old)/x3;
if(error<0)error=error*(-1);
if( error < 0.001 )
break;
}
}
printf("\n선형보간법");
printf("\n횟수 : %d", count);
printf("\n근 : %g", x3);
printf("\n오차백분율 : %g\n\n", 100*error);
//NEWTON법
x1=-0.5;
x2=1.5;
count=0;
x3=0;
for(count = 0; count < MAX_I; count++) {
f1 = poly_f(x1);
f2 = poly_f(x2);
x3_old = x3;
x3 = x2 - (x2 - x1)/(f2 - f1)*f2;
x1 = x2;
참고 자료
없음