Newton Raphson method로 문제푸는거요...
바나나맛캔디
2023.04.01
y=3logx-sin^2x의 근을 구하는 프로그램 작성인데요Initial guess :Tolerance :root: 제가 만든 소스인데..안되네요;;머가잘못된걸까요ㅜ#include stdio.h
#include math.hint main(void)
{
double y, yd, x_1, e;
double x;
printf(Newton Raphson Method for fx=0 \n\n);
printf(Initial guess : );
scanf(%f,&x);
printf(Tolerance : );
scanf(%f,&e);
do
{
y = 3*log(x)-pow(sin(x),2);
yd = 3/x-sin(2*x);
x_1=x;
x=x-(y/yd);
e=x_1-x;
}
while (fabs(e)e);
printf(root %f\n, x);
return 0;
}
-
창의적
1. scanf 로 double 변수에 값을 입력 받으려면, %lf 를 사용해야 합니다.
2. tolerance 를 저장하는 e 와 x 의 값의 증분을 나타내는 e를 별도로 다른 변수를 사용하세요.