목차
1. 문제 및 결과
(a) 황금분할탐색법(xl = -2, xu = 4, εs = 1%)
(b) 뉴튼(Newton) 법(X0 = 3, εs = 1%)
(a) 황금분할탐색법(xl = -2, xu = 4, εs = 1%)
(b) 뉴튼(Newton) 법(X0 = 3, εs = 1%)
본문내용
es)//뉴튼 메서드
{
double ea=100;//ea 초기값
int iter=0;//iter 초기값
double xold=0,xnew=firstX;//xold와 xnew의 초기값
while(ea>es&&iteres&&iter
{
xold = xnew;//xold에 x0값 대입
xnew = xold - f1(xold)/f2(xold);//xnew 값 구하는 식
ea= ((xnew-xold)/xnew)*100;//ea 구하는 식
if(ea < 0)//ea<0 일때 양수로 바꾸어줌
ea=-ea;
iter++;//iter횟수 증가
String str1 = String.format("%.6f", xnew);//6번째 소수점아래 자리까지만 보이기
String str2 = String.format("%.6f", xold);//6번째 소수점아래 자리까지만 보이기
System.out.println("\n시행횟수 = "+iter+"\nf'(x) = "+f1(xold)
+"\nf''(x) = "+f2(xold)+"\nxold = "+str2+"\nxnew = "+str1+"\nea = "+ea);//출력
}
String str1 = String.format("%.6f", xnew);//6번째 소수점아래 자리까지만 보이기
System.out.println("\n-----------최종값-------------");//최종 출력
System.out.println("\n총 시행횟수 = "+iter+"\nx = "+str1+"\nea = "+ea);
}
}
2. 결과값 도출
{
double ea=100;//ea 초기값
int iter=0;//iter 초기값
double xold=0,xnew=firstX;//xold와 xnew의 초기값
while(ea>es&&iter
xold = xnew;//xold에 x0값 대입
xnew = xold - f1(xold)/f2(xold);//xnew 값 구하는 식
ea= ((xnew-xold)/xnew)*100;//ea 구하는 식
if(ea < 0)//ea<0 일때 양수로 바꾸어줌
ea=-ea;
iter++;//iter횟수 증가
String str1 = String.format("%.6f", xnew);//6번째 소수점아래 자리까지만 보이기
String str2 = String.format("%.6f", xold);//6번째 소수점아래 자리까지만 보이기
System.out.println("\n시행횟수 = "+iter+"\nf'(x) = "+f1(xold)
+"\nf''(x) = "+f2(xold)+"\nxold = "+str2+"\nxnew = "+str1+"\nea = "+ea);//출력
}
String str1 = String.format("%.6f", xnew);//6번째 소수점아래 자리까지만 보이기
System.out.println("\n-----------최종값-------------");//최종 출력
System.out.println("\n총 시행횟수 = "+iter+"\nx = "+str1+"\nea = "+ea);
}
}
2. 결과값 도출
소개글