I have some errors that I can't seem to understand, could someone help me clear up this problem?
#include <cmath>
#include <iostream>
using namespace std;
double F ( double X )
{
return pow ( X, 4) - 9*pow ( X, 3 ) - 2*pow (X, 2) + 120*X - 130;
}
double DF (double X)
{
return 4*pow (X, 3) - 27*pow (X, 2) - 4*X + 120;
}
double DDF (double X)
{
return 12*pow (X, 2) - 54*X -4;
}
int main()
{
int TALLEY;
double X, XL, XR, XS, Y, YL, YR;
double XB, XND, STEPSIZE;
double XO, XN, FX, DFX, DDFX;
double INT_ACC, ROOT_ACC, TOO_BIG, TOO_SMALL;
TALLEY = 0;
XL = 0.0;
XR = 0.0;
XS = 0.0;
X = 0.0;
Y = 0.0;
YL = 0.0;
YR = 0.0;
XB = 0.0;
XND = 0.0;
STEPSIZE = 0.0;
XO = 0.0;
XN = 0.0;
FX = 0.0;
DFX = 0.0;
DDFX = 0.0;
INT_ACC = 0.0;
ROOT_ACC = 0.0;
TOO_BIG = 0.0;
TOO_SMALL = 0.0;
cout<<"What is the left-most interval endpoint? ";
cin>> XB;
cout<<"What is the right-most interval endpoint? ";
cin>> XND;
cout<<"What is the desired step-size for function evaluation? ";
cin>> STEPSIZE;
cout<<"How close can the approximate root be to the true root to invoke root-finding? ";
cin>> INT_ACC;
cout<<"What is the size limit on the 2nd derivative? ";
cin>> TOO_BIG;
cout<<"How close can the 1st derivative get to zero? ";
cin>> TOO_SMALL;
cout<<"What is the desired accuracy for root-finding? ";
cin>> ROOT_ACC;
XL = XB;
while ( true ) {
YL = F ( XL );
XR = XL + STEPSIZE;
YR = F ( XR );
if ( YL * YR > 0 ) {
if ( XR >= XND ) goto end;
XL = XR;
YL = YR;
}
if ( YL * YR == 0 ) {
if ( YL == 0.0 ) {
cout<<"This is a root. "<< XL<<endl;
if ( XR >= XND ) goto end;
XL = XR;
}
else {
cout<<"This is a root. "<< XR<<endl;
if ( XR >= XND ) goto end;
XL = XR + STEPSIZE;
}
}
if ( YL * YR < 0 ) {
XS = XR;
while ( true ) {
X = ( XL + XR ) / 2.0;
Y = F ( X );
if ( YL * Y > 0 ) {
XL = X;
YL = Y;
}
if ( YL * Y == 0 ) {
cout<<"This is a root. "<< X<<endl;
XR = X;
YR = Y;
}
if ( YL * Y < 0 ) {
XR = X;
YR = Y;
}
if ( fabs(XR - XL) < INT_ACC) {
cout<<"This interval contains a root at "<< XL <<','<< XR<<endl;
XO = (XL + XR)/2.0;
TALLEY = 1;
while ( true ) {
FX = F(XO);
DFX = DF(XO);
DDFX= DDF(XO);
if (fabs(DDFX)>= TOO_BIG) {
cout<<"Condition 1 FAILS: 2nd derivative too large. ";
}
}
if (fabs(DFX) <= TOO_SMALL) {
cout<<"Condition 2 FAILS: 1st derivative too close to zero. ";
}
}
if (TALLEY > 15) {
cout<<"Slow convergence. Possible infinite loop.";
}
}
XN = XO - (FX/DFX);
if (fabs(XN-XO) < ROOT_ACC) {
cout<<"The root is: "<<XN<<endl;
}
else
XO = XN;
TALLEY = TALLEY + 1;
}
}
XL = XS;
if ( XL >= XND ) goto end;
break;
}
}
}
}
}
end:
return 0;
}
Here are the errors that are shown:
F:\C ++ Numerical Methods\Newton_Raphson.cpp(183) : error C2043: illegal break
F:\C ++ Numerical Methods\Newton_Raphson.cpp(184) : warning C4508: 'main' : function should return a value; 'void' return type assumed
F:\C ++ Numerical Methods\Newton_Raphson.cpp(185) : error C2143: syntax error : missing ';' before '}'
F:\C ++ Numerical Methods\Newton_Raphson.cpp(185) : error C2143: syntax error : missing ';' before '}'
F:\C ++ Numerical Methods\Newton_Raphson.cpp(185) : error C2143: syntax error : missing ';' before '}'
F:\C ++ Numerical Methods\Newton_Raphson.cpp(186) : error C2143: syntax error : missing ';' before '}'
F:\C ++ Numerical Methods\Newton_Raphson.cpp(186) : error C2143: syntax error : missing ';' before '}'
F:\C ++ Numerical Methods\Newton_Raphson.cpp(187) : error C2143: syntax error : missing ';' before '}'
F:\C ++ Numerical Methods\Newton_Raphson.cpp(187) : error C2143: syntax error : missing ';' before '}'
F:\C ++ Numerical Methods\Newton_Raphson.cpp(188) : error C2143: syntax error : missing ';' before '}'
F:\C ++ Numerical Methods\Newton_Raphson.cpp(188) : error C2143: syntax error : missing ';' before '}'
F:\C ++ Numerical Methods\Newton_Raphson.cpp(192) : error C2143: syntax error : missing ';' before 'return'
F:\C ++ Numerical Methods\Newton_Raphson.cpp(193) : error C2143: syntax error : missing ';' before '}'
F:\C ++ Numerical Methods\Newton_Raphson.cpp(193) : error C2143: syntax error : missing ';' before '}'
F:\C ++ Numerical Methods\Newton_Raphson.cpp(193) : error C2143: syntax error : missing ';' before '}'
Error executing cl.exe.
Newton_Raphson.obj - 14 error(s), 1 warning(s)