How do you do this?

  • Thread starter tidus_yuna_thespring
  • Start date
T

tidus_yuna_thespring

I'm a beginner C++ programmer. I would like to ask for help for a
particular assignment. My teacher assigned a Mini Program for us to
do. Here's the link to the question:

http://www.geocities.com/swnwtinecho/sample.html

Can someone pls. help me how to do this? Or suggest how to start it?
I'm not asking for the code, I'm just want to know how to start it as I
am real confused about this particular problem. APPRECIATE ANY HELP.

R,
Christian
 
A

andy

I'm a beginner C++ programmer. I would like to ask for help for a
particular assignment. My teacher assigned a Mini Program for us to
do. Here's the link to the question:

http://www.geocities.com/swnwtinecho/sample.html

Can someone pls. help me how to do this? Or suggest how to start it?
I'm not asking for the code, I'm just want to know how to start it as I
am real confused about this particular problem. APPRECIATE ANY HELP.

R,
Christian

This is a Maths problem really. Whatever... First you need starting
values for X.

What is a good first approximation to X?

regards
Andy Little
 
T

tidus_yuna_thespring

Oops...I forgot to mention...I have to write a code to solve for this
particular problem...can someone give me a head start? I'm confused.
Appreciate any help
 
T

tidus_yuna_thespring

Oops...I forgot to mention...I have to write a code to solve for this
particular problem...can someone give me a head start? Again, I'm not
asking for the code...just how to start it. I'm confused. Appreciate
any help
 
S

Stuart Golodetz

Oops...I forgot to mention...I have to write a code to solve for this
particular problem...can someone give me a head start? I'm confused.
Appreciate any help

(Please don't top-post - it makes life difficult for people)

This is fairly off-topic here (hence the [OT] I've added in the subject
line), but since you've basically been given the algorithm to solve the
problem, I'll give you the benefit of the doubt and assume that you're
having trouble expressing it in code.

What you seem to need is some advice about problem-solving. The code to
solve this is not especially difficult and you're not required to understand
the algorithm in detail (they've given you everything you need - you don't
even have to differentiate the function).

The way to solve problems is to break them up into pieces - divide and
conquer. Your first step is generally to start with:

int main()
{
return 0;
}

If you can't get this far, then this problem isn't what you're having
difficulty with - you need a book on C++. More importantly, you need to read
it.

The next step is to look at the algorithm you've been given: you start from
an initial value of x and keep iterating it until (hopefully) it converges
to one of the values you're looking for. Ok, so we write a function which
looks like:

double specific_newton_raphson(double x)
{
....
}

This takes an initial value of x (a double) and returns our final
approximation to the root (also a double).

Given that one of the roots is positive and one is negative, you might come
up with the idea of trying 1 and -1 as the initial approximations to find
each of the roots (this might not be right, but it's worth a try and in this
case it works - if it didn't, you could draw the function (perhaps) and make
a more educated guess). So we change our main function as follows:

int main()
{
std::cout << specific_newton_raphson(1.0) << '\n';
std::cout << specific_newton_raphson(-1.0) << '\n';
return 0;
}

This outputs the results of running the iteration starting from 1 and -1,
respectively. So far, so good. Now we actually need to do the iterating
(i.e. fill in the body of the specific_newton_raphson function). I'm not
going to do that bit for you, but I will give you an idea (a pretty good
idea, actually) of how you might go about it:

double specific_newton_raphson(double x)
{
const double EPSILON = 0.0001;

double oldX;
do
{
// store the current value of x in oldX and update x as per the
question
} while(fabs(x - oldX) > EPSILON); // continue until two successive
iterations are close enough together

return x;
}

Hope this helps,
Stu

P.S. You'll need to include iostream and cmath to get this to work.
 
O

osmium

I'm a beginner C++ programmer. I would like to ask for help for a
particular assignment. My teacher assigned a Mini Program for us to
do. Here's the link to the question:

http://www.geocities.com/swnwtinecho/sample.html

Can someone pls. help me how to do this? Or suggest how to start it?
I'm not asking for the code, I'm just want to know how to start it as I
am real confused about this particular problem. APPRECIATE ANY HELP.

That question - as worded - should not have been assigned to you unless a
pre-requisite for the course is calculus - which would be quite unusual. A
person who does not know the basics of calculus can not even *read* the damn
question.

In y'(X) I think he meant y'(X) where ' means the first derivative.

You may be better off by simply ignoring the first paragraph and the first
equation - pretend you didn't see them..

However, you have been given good advice here and you should be able to
muddle through despite this. A similar thing happened to a friend of mine
and he got together with some other guys in the course and they sued (or
threatened to) the University to get their money back. He got his money back
for the course. He already had a degree but it was in English.
 
A

Alf P. Steinbach

* osmium:
That question - as worded - should not have been assigned to you unless a
pre-requisite for the course is calculus - which would be quite unusual. A
person who does not know the basics of calculus can not even *read* the damn
question.

Well, at most it's high school stuff, not college level stuff. I did
this in high school, one of my first programs (in Basic). I'd done it
in secondary school were it not for the lack of a computer, and were it
not for my reaction at that time to my secondary school math teacher's
exposition of the Newton-Raphson method: "why, that's /cheating/" (I
thought every equation had to be solved symbolically)...

I think someone starting out in C++ should at least be finished with
secondary school.

Except for those with unusually high interest in maths and programming.

In y'(X) I think he meant y'(X) where ' means the first derivative.


y' means the first derivative. y'(X) means the first derivative at
point X. It helps to draw the situation (essentially a better
approximation is obtained by drawing a tangent to the graph of y(x) at
point X and choosing X[i+1] as the point where that tangent crosses
the x-axis), and to understand how differentiation can be approximated
by, guess what, differences.

I'm setting follow-ups to [comp.programming].
 
J

Joe Van Dyk

Alf said:
* osmium:



Well, at most it's high school stuff, not college level stuff. I did
this in high school, one of my first programs (in Basic). I'd done it
in secondary school were it not for the lack of a computer, and were it
not for my reaction at that time to my secondary school math teacher's
exposition of the Newton-Raphson method: "why, that's /cheating/" (I
thought every equation had to be solved symbolically)...

For most (american) students, first exposure to Calculus comes in
college/university, not high school. Calculus was a AP course in my
high school.

Joe
 
A

Alf P. Steinbach

* Joe Van Dyk:
For most (american) students, first exposure to Calculus comes in
college/university, not high school. Calculus was a AP course in my
high school.

Different in Norway. Basic calculus is high school level; I also had
differential equations and Laplace transforms as an optional in high
school. However, we're worried about the extreme decline of our
educational system wrt. science. It turns out that most of those who
study to become teachers now, don't even master basic fractions, primary
school stuff. This after a number of reforms where the basic idea seems
to have been to create people with good/better social skills. Not a bad
idea per se, but it seems that it's been pushed too hard for too long.
 
M

Mark P

Alf said:
* Joe Van Dyk:

Different in Norway. Basic calculus is high school level; I also had
differential equations and Laplace transforms as an optional in high
school. However, we're worried about the extreme decline of our
educational system wrt. science. It turns out that most of those who
study to become teachers now, don't even master basic fractions, primary
school stuff. This after a number of reforms where the basic idea seems
to have been to create people with good/better social skills. Not a bad
idea per se, but it seems that it's been pushed too hard for too long.

I'm in the U.S. and I'm with Alf on this. Many seniors in my HS took
calculus (I went beyond calculus in HS but I'll concede that that's
uncommon), and when I got to college most freshmen with a math/science
inclination had already taken calculus in HS. In fact there's a common
HS course before calculus called, fittingly, pre-calculus which covers
very basic concepts from calculus and IIRC Newton-Rhapson was covered
there too.
 
M

Marcus Kwok

Mark P said:
In fact there's a common
HS course before calculus called, fittingly, pre-calculus which covers
very basic concepts from calculus and IIRC Newton-Rhapson was covered
there too.

I am in the US too, except our pre-calculus class was called "Analysis"
(not to be confused with an upper-level course of the same name).
 
J

Joe Van Dyk

Mark said:
I'm in the U.S. and I'm with Alf on this. Many seniors in my HS took
calculus (I went beyond calculus in HS but I'll concede that that's
uncommon), and when I got to college most freshmen with a math/science
inclination had already taken calculus in HS. In fact there's a common
HS course before calculus called, fittingly, pre-calculus which covers
very basic concepts from calculus and IIRC Newton-Rhapson was covered
there too.

Pre-calculus was standard for high school seniors at my U.S. school.

Joe
 

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
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top