hi, im a beginner in using C++...

i have a project due in a few days and i've been trying to do the program for a week now... we're supposed to make a program that would allow the user to enter any polynomial equation (always = 0), asks the user the interval and number of iterations and solve it using secant method...

for example, the user entered the polynomial equation of 0.5x^4 + 2x^2 - x + 4 = 0, interval [-0.25, 0], no of iterations is 5, the result should be the following:

[IMG]http://i37.tinypic.com/339qefn.jpg[/IMG]

the screen should look like this when program is run:

[IMG]http://i33.tinypic.com/3325hs4.jpg[/IMG]

i already have a code for the secant method formula part for computing the new x sub n, however i don't have a clue as to how i would make a code enabling the user to enter the polynomial equation to be solved and substituting the new x (which is the new computed x sub n obtained from the secant formula) to the polynomial equation…

the question is what I want possible?... is there any kind of library that I need for wat I want?..

hope u guys can help coz honestly im no good in programming… I'm getting crazy with this project coz due is in 2 days time (sobs)… please help…

for additional information, for the secant part of the program… the code is the following:

``````for(int i=1;i<=n;i++)
{
c[i+1]=c[i]-(f(c[i]) * (c[i]-c[i-1])) / (f(c[i])-f(c[i-1]));
cout <<"c(" << i+1 <<") = "<< c[i+1] <<"\n";
}``````
2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by iamthwee

http://en.wikipedia.org/wiki/Secant_method

If you look at the following web page you can see a sample bit of code which does what you probably need.

However, you say that you want to allow the user to enter the function at run time whereas in that web-page the function was hard coded.

In order to do something like allowing the user to enter the function at run time you will NEED to write an expression parser.

Choices are most commonly,

i) Reverse Polish notation using stacks/queues
ii) Reverse Polish notation using expression trees.

Now, writing an expression parser is no easy task- (Even a trivial parser, which doesn't account for trig functions or complex numbers.) If you have two days left to complete this I would abandon the idea and just submit your project with the hard coded expression as a function in your c++ file.

Ideally, your teacher should have hinted to, if indeed an expression parser is what you need to be writing.

I don't believe there are any libraries out there that do this. Even if there were, you probably wouldn't be able to use them for this project.

Edited by iamthwee: n/a

the deadline was moved and we were given about 5 days more...
is there a way that i could do wat needs to be done within that time period?..
also... cud u explain to me clearly wat needs to be done?..
please... i wud really appreciate any help i cud get... thanks