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

C program that uses Newton's Method to solve an equation

P: 1
Write a C program that uses Newton's Method to solve an equation in one variable.

Try solving x^x = ln2

the deriviative of x^x is x^x(lnx + 1). The 'ln' function in C is log(), and the value
for ln2 is approximately .693147180559945 (to 15 places, about the limit of double precision).

Test for convergence using a tolerance of about 1e-10 (that is, look at the absolute value of
new_x - old_x and require this to be less than 1e-10 to say it has converged). Also keep a count
of the number of iterations; if this goes over 100, announce that there is no convergence. Otherwise
once you have convergence, print the solution (say to 15 places) and the number of iterations
Sep 15 '06 #1
Share this Question
Share on Google+
7 Replies


Banfa
Expert Mod 5K+
P: 8,916
Have an attempt first yourself

Do you mean the Newton Method or the Newton Raphson method?

Newton method finds points on a curve which are a minimum or maximum, the Newton Raphson method finds roots of equations.

Either way you need to be able to write you equation with a 0 on 1 side before deriving it and the Newton method involves a double derrivation.

Netwon Method: next x = 1 - f'(x)/f''(x)

Netwon Raphson Method: next x = 1 - f(x)/f'(x)

Newton Raphson method you have to be sure that there is a root, with the Newton method you have to be sure that there is a stationary point.

There is little point printing the answer to 15 decimal places when you only have a tolerance of 10.

Once you have made an attempt then post your code an we will help you fix problems and make it work.
Sep 15 '06 #2

P: 6
:: full code removed per Posting Guidelines::

IS THIS CORRECT ????????????????
Mar 15 '07 #3

sicarie
Expert Mod 2.5K+
P: 4,677
Did you try running it through a compiler?
Mar 15 '07 #4

P: 2
hi my friends
i am a new member in this site and i wana help as fast as possible...........pleaaaaaaaaaaaaaaaaas?


how to write this function in c++ by using Newtton raphson method?
*the question is:

Write a program that uses Newton-Raphson Method to approximate the root of a function
we could execute an infinite number of iterations to find a perfect representation for the root of our function. However, we will assume that the process has worked accurately when x = xk+1- xk becomes less than 0.1
To see how this works, we will perform the Newton-Raphson method on the function f(x) = x2-4. Below are listed the values that we need to know in order to complete the process:
f(x) = x2-4
f'(x) = 2x
x1 = 6



*the answer should be:

Newton-Raphson Method to approximate the root of a function

- Enter precision (1/10, 1/100, 1/1000,...): 0.1

xk f(x) derived_f(xk) xk+1 dx
6.000 32.000 12.000 3.333 2.667
3.333 7.111 6.667 2.267 1.067
2.267 1.138 4.533 2.016 0.251
2.016 0.063 4.031 2.000 0.016
- Enter your choice: (q) to quit, (c) to continue: c

- Enter precision (1/10, 1/100, 1/1000,...): 0.01

xk f(x) derived_f(xk) xk+1 dx
6.000 32.000 12.000 3.333 2.667
3.333 7.111 6.667 2.267 1.067
2.267 1.138 4.533 2.016 0.251
2.016 0.063 4.031 2.000 0.016
2.000 0.000 4.000 2.000 0.000




please dont be late?
Apr 10 '07 #5

sicarie
Expert Mod 2.5K+
P: 4,677
fahman-

It's considered rude to ask your question in someone else's thread. Please look at our Posting Guidelines, read this thread (if it is applicable - I didn't check), try the methods in here, and create a new thread with your specific question and code snippet of where you're stuck fi you still need help.
Apr 10 '07 #6

P: 2
hi my friend
in this q i didnot understand how to write the formula because ther are alot of varialbe

please can write it to me?
Apr 11 '07 #7

Ganon11
Expert 2.5K+
P: 3,652
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

Then when you are ready post a new question in your own thread.

MODERATOR
Apr 11 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.