Thread: roota of an equation

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    1

    roota of an equation

    Good morning sir,
    Iam new to the c i need a help from u. I dont know the roots of an equation in c program language so i kindly requested u to give the solution.




    Thank you sir

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    How would you do it in math? If you know how to find the roots, mathematically, it's easy to convert that into functions. If not then no knowlege of C will help you.

    Though I guess you could always use the brute force aproach.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > so i kindly requested u to give the solution.
    http://cboard.cprogramming.com/annou...t.php?f=4&a=39
    http://cboard.cprogramming.com/annou...t.php?f=4&a=51
    Make an effort, then we will help you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    You could use the Newton-Raphson method.
    double solve (double (*) (double), double low, double high);

  6. #6
    Registered User
    Join Date
    Dec 2006
    Posts
    1
    1) If the problem states that there is just one root in a given interval, like [a,b], than the solution is straightforward: you just have to use the bisection method.
    2) You should take great care when using Newton-Raphson method (a badly designed algorithm implementing Newton-Raphson method will go, for certain roots, to infinity)
    Last edited by rieman; 12-16-2006 at 08:01 AM.

  7. #7
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    1) If the problem states that there is just one root in a given interval, like [a,b], than the solution is straightforward: you just have to use the bisection method.
    2) You should take great care when using Newton-Raphson method (a badly designed algorithm implementing Newton-Raphson method will go, for certain roots, to infinity)
    Actually, bisection will only work if there are at least two points in your interval for which their y-value is of opposite sign. An interval can have one root in it, but if the signs never change in that interval, your bisection method will do much worse than Newton-Raphson (namely, it will crash or have undefined behaviour.)

    Also, to avoid all these infinity deals, usually what's best is to see if you reach a fix point after a certain number of iterations.

    If I was you, doing a homework assignment, I'd simply do bisection, unless order of convergence and efficiency are THAT important to you.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help needed! Finding Root of an Equation?
    By reader in forum C Programming
    Replies: 4
    Last Post: 06-13-2008, 10:10 AM
  2. Replies: 15
    Last Post: 11-04-2006, 04:06 AM
  3. IDEA: Equation solver
    By Magos in forum Contests Board
    Replies: 2
    Last Post: 01-07-2003, 11:46 AM
  4. Quadratic Equation Program
    By Ambizzy in forum C Programming
    Replies: 4
    Last Post: 02-19-2002, 09:21 PM
  5. equation solving
    By ajlott_coder in forum C Programming
    Replies: 6
    Last Post: 01-26-2002, 02:34 AM