수치해석
- 최초 등록일
- 2011.06.21
- 최종 저작일
- 2011.05
- 9페이지/ 한컴오피스
- 가격 2,000원
소개글
이분법, 가위치법, 할선법, 뉴턴법 C++ 소스파일
목차
1. 이분법
2. 가위치법
3. 할선법
4. 뉴턴법
본문내용
1. 이분법
#include "stdafx.h"
#include<iostream> //입출력 사용
#include<cmath> //수학적 함수사용
using namespace std;
#define MAXITER 50
#define EPS 1.0e-10//define accuracy of convergence
//define the f(x) function
double f(double x){
return (x-cos(x)); // cos 수식함수 이용하여 f(x) 함수 설정
}
double bisect(double a,double b){
int n;
double c;
for(n=0;n<MAXITER;n++){
c=(a+b)/2.0;
if(fabs(f(c))<EPS)break //break if solution becomes close to the convergence point(root)
if(f(a)*f(c)<0.0)b=c;
else a=c;
}
return c;
}
int main(void){
double a,b,root;
cout<<"Enter 2 starting values : "<<endl;
//define the two starting points
cout<<"A : "
cin>>a;
cout<<"B : "
cin>>b;
root = bisect(a,b);
cout<<"Root is at : "<<root<<endl;
return 0;
참고 자료
없음