help on finding root using newton raphon method

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 3
Reputation: nosa2008 is an unknown quantity at this point 
Solved Threads: 0
nosa2008 nosa2008 is offline Offline
Newbie Poster

help on finding root using newton raphon method

 
0
  #1
Oct 14th, 2008
i have this function f(x)= e^X-3X^2
I need to write a computer program that find all three roots by the use of newton raphson method and option of finding a root by use of fixed point iteration.

this is all i came up with so far..
i need help...
  1. #include <iostream.h>
  2. #include<iomanip>
  3. #include<math.h>
  4.  
  5. using namespace std;
  6.  
  7. //(&f) (x) reference to function f(x)//
  8. //(fdiv)(x) reference to function f'(x)//
  9. double x;
  10. double func_1;
  11. doublefdiv_1;
  12.  
  13. //............................................................//
  14. //test function
  15.  
  16. double func_1(double x)
  17. {
  18. return (e^x-3x^2);
  19. //f(x)=e^x-3x^2=0
  20. }
  21. double fdiv_1(double x)
  22. {
  23. return (e^x-6x);
  24. // f'(x)=e^x-6x
i dont know if i am starting the program right.. i need help on how to start the program
Last edited by Narue; Oct 14th, 2008 at 4:05 pm. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 390
Reputation: skatamatic will become famous soon enough skatamatic will become famous soon enough 
Solved Threads: 39
skatamatic skatamatic is offline Offline
Posting Whiz

Re: help on finding root using newton raphon method

 
0
  #2
Oct 14th, 2008
Hmmm. I don't think that the ^ operator works in c++. I could be wrong =\ , but I think you must use the POW func in the cmath header. I think that ^ is some sort of bitwise XOR or XNOR or something of the sort.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 390
Reputation: skatamatic will become famous soon enough skatamatic will become famous soon enough 
Solved Threads: 39
skatamatic skatamatic is offline Offline
Posting Whiz

Re: help on finding root using newton raphon method

 
0
  #3
Oct 14th, 2008
I have no idea what that method of finding roots is, perhaps explain in detail what you need to do and I can help translate it into c++ code.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: help on finding root using newton raphon method

 
0
  #4
Oct 14th, 2008
indeed, you must use the cmath header...

pow() and also sqrt() will find the square root of a number xD

pow takes to aruments first is the number to be raised to the powerof the second number if that makes sense.

Also i should talk about the chain rule.

the chain rule can be used to find the derivative of (ax+b)^z in a few simple steps.
It also applies to finding the derivative of e^(x-3x^2) in your case

the chain rule is this

dy/dx = du/dx * dy/du

now where does you come into well we set the power of e = u so

e^(x-3x^2) becomes
u = x-3x^2

therefore, we get this

f(x) = e^u therefore dy/du = e^u.

but we must find the derivative of u

u = x-3x^2
du/dx = x-6x

so back to the chain rule.

dy/dx = du/dx * dy/du

dy/dx = (x-6x) * (e^u)

dy/dx = (x-6x)(e^(x-3x^2))

Hope that helps you with finding the correct derivative.

Chris
Last edited by Freaky_Chris; Oct 14th, 2008 at 5:02 pm.
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC