Need with with some errors

A

Andrew

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.
 
D

David Harmon

On 21 Mar 2007 16:54:04 -0700 in comp.lang.c++, "Andrew"
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.
 
X

xperthands

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?

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

double getdF( x )

This is line 33: do you see the problem here?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top