By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,120 Members | 1,257 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,120 IT Pros & Developers. It's quick & easy.

Need with with some errors

P: n/a
Hi, I am trying to write a program to solve roots using the Newtonian
method of roots, and I am recieving several errors which I cannot
figure out... if anyone could give me a point in the right direction
it wuld be appreciaed.

Here is what I have so far:

#include <iostream>
#include <math.h>
using namespace std;

double getF(double x); //The orgional function
double getdF(double x); //The derivative of orgional function

//int getRoot(double &rootEst, double tolerance, int maxIterations);

const double e = 2.718281828459;

double getRoot(double &rootEst, double tolerance, int maxIterations)
{
int n = 1;

while( ( fabs(getF(rootEst)) tolerance ) && ( n <=
maxIterations ) )
{
rootEst = rootEst - ( getF(rootEst) / getFd(rootEst) );

n++;
}
return n;
}

double getF( x )
{
return ( pow(x, 2) * pow(e, -1 * x) - 2 );
}

double getdF( x )
{
return ( 2 * pow(e, -1 * x) * x - pow(x, 2) * pow(e, -x) );
}

int main () {

double rootEst, //The initial estimate of the root
tolerance; //The stopping tolerance
int maxIterations,
curNumIterations;

cout << "Please enter the initial estimate of the root: ";
cin >rootEst;

cout << "Please enter the tolerance: ";
cin >tolerance;

cout << "Please enter the maximum allowed iterations: ";
cin >maxIterations;

cout << endl << "Using the following data" << endl
<< "Initial guess: " << rootEst << endl
<< "Tolerance: " << tolerance << ", and" << endl
<< "Maximum iterations: " << maxIterations << "." << endl;

curNumIterations = getRoot(rootEst, tolerance, maxIterations);

if(curNumIterations maxIterations) {
cout << "After " << maxIterations << " iterations no solution was
found!" << endl;
}
else {
cout << "The solution is: " << rootEst << " and it was found in "
<< curNumIterations << " iterations" << endl;
}

return 0;

}

And here are my compile errors:

------ Build started: Project: test, Configuration: Debug Win32 ------
Compiling...
assign8.cpp
..\assign8.cpp(18) : error C3861: 'getFd': identifier not found
..\assign8.cpp(27) : error C2065: 'x' : undeclared identifier
..\assign8.cpp(28) : error C2448: 'getF' : function-style initializer
appears to be a function definition
..\assign8.cpp(33) : error C2448: 'getdF' : function-style initializer
appears to be a function definition
Build log was saved at "file://c:\Documents and Settings\Janet Lannon
\My Documents\Visual Studio 2005\Projects\test\test\Debug
\BuildLog.htm"
test - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========
I am a student and new to this, im not looking for someone to give me
the complete solution, but hopefully help me realise whats wong with
my own. thanks.

Mar 21 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 21 Mar 2007 16:54:04 -0700 in comp.lang.c++, "Andrew"
<an*********@gmail.comwrote,
>And here are my compile errors:

------ Build started: Project: test, Configuration: Debug Win32 ------
Compiling...
assign8.cpp
.\assign8.cpp(18) : error C3861: 'getFd': identifier not found
What could be more clear?

You try to call getFd().
You never defined anything with that (exact) name.
Mar 22 '07 #2

P: n/a
On Mar 21, 4:54 pm, "Andrew" <andrew.b...@gmail.comwrote:
<snip>
rootEst = rootEst - ( getF(rootEst) / getFd(rootEst) );
This is line 18 in your program. Look at the first error
message, now look at the actual function name... do you
see the discrepancy?

<snip>
double getF( x )
This is line 27 of your program. I think you're missing
a type specifier... The error on line 28 is just
collateral damage from this error

<snip>
double getdF( x )
This is line 33: do you see the problem here?

Mar 22 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.