Okay finally got this program done there is only one problem, it goes only to 4.0000 And I need it to go all the way down to zero or very close to it. My eyes are bloodshot and I need some help with this thing :-) Thanks in advance
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define STOP 0.001
double func1 (double x);
double func2 (double x);
double Xro, Xrn, EPS, fXro, fprimeXro;
int Iter,q;
void main(void)
{
FILE *outptr;
outptr=fopen("output.txt","wt");
label3: printf("\nPlease enter a value for Xro");
scanf("%lf",&Xro);
printf("\nYou entered Xro= %lf", Xro);
fprintf(outptr, "\nThe intial guess is Xro= %lf ", Xro);
Iter=1;
fprintf(outptr,"\nIter Xro Xrn error");
label1: fXro = func1(Xro);
fprimeXro = func2(Xro);
if (fprimeXro == 0.0) {
printf ("\n The slope of a function at iteratuin number =%4d\
\nis equal to zero. Newton-Raphson Method fails. Program is\
\ngoing to prompt you to start a new initial guess!",Iter);
goto label3;
}
Xrn = Xro -fXro/fprimeXro;
printf("\nThe new estimate of the root is = %lf", Xrn);
EPS = fabs((( Xrn - Xro)/Xro)*100.);
fprintf (outptr,"\n%4d %12.9f %12.9f %12.9f\
",Iter,Xro,Xrn,EPS);
Iter = Iter + 1;
printf("Do you wish to exit, if so press 0");
scanf("%li", &q);
if (q==0) {
return;
}
if ( EPS <= STOP ) {
printf ("\nRoot = %lf",Xrn);
fprintf (outptr,"\nRoot is = %lf", Xrn);
goto label2;
}
else {
Xro = Xrn;
goto label1;
}
label2:
fclose(outptr);
getch();
}
double func1(double x)
{
return( pow(x,2.0) - x -12. );
}
double func2(double x)
{
return( 2.0*x - 1.0);
}