/*T Math/CS 466/666 Midterm Solutions \medskip\noindent Problem 1(i). Write or modify a computer program to implement Newton's method and use it to approximate the solution to $x^3=\cos x$ starting with an initial guess of $x_0=1.$ Print the first 5 iterations of the method. */ #include #include double f(double x){ return x*x*x-cos(x); } double df(double x){ //T Always set this to $f'(x)$ where $f(x)$ is defined above. return 3*x*x+sin(x); } int main(){ printf( "Math/CS 466/666 Midterm\nProblem 1(i).\n\n" "%3s %24s\n","n","xn"); double x=1; for(int i=0;;i++){ printf("%3d %24.14e\n",i,x); if(i>=5) break; x=x-f(x)/df(x); //T $x_{i+1}=x_{i}-f(x_i)/f'(x_i)$ } }