Thread: implementing square root function

  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    50

    implementing square root function

    Hi guys, Im facing a serious problem and not finding an optimal way to solve it , I have to implement square root function that gets in its input double x , double toleration and the output must be the value of square root of value x , I musn't use any already built up function like pow or square , I just must use operation / + - *

    the toleration parameter is actually how much error deviation possibility , I mean lets assume toleration is 0.1 , and value x is 10 then 3+0.1 is acceptable and 3-0.1 also acceptable .. toleration is the deviation of your error from the correct value of the square root of x ..

    thanks alot!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.

  3. #3
    Registered User
    Join Date
    Nov 2019
    Posts
    50
    Quote Originally Posted by Salem View Post
    didn't understand anything there, wtf it's really complicated ..

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It is mathematics that I was taught in school when I was 15 years old. Anyway, you don't really need to understand the maths beyond knowing that it is an iterative method that is kind of a sophisticated take on the "guess and check" strategy; just implement the given recurrence relation with an initial guess.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Nov 2019
    Posts
    50
    Quote Originally Posted by laserlight View Post
    It is mathematics that I was taught in school when I was 15 years old. Anyway, you don't really need to understand the maths beyond knowing that it is an iterative method that is kind of a sophisticated take on the "guess and check" strategy; just implement the given recurrence relation with an initial guess.
    I may didn't understand the algorithm itself, it sounds complicated for me but actually from your words it's not, could you explain it for me in brief words? thanks

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No, work through the Wikipedia example instead. It provides a better explanation of what to implement than I could say "in brief words".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Lazy people are like horses! You can lead them to water; but, you can't make them drink.

    Hint: The sample Julia code should help anyone who has the ability to learn to code!

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > didn't understand anything there, wtf it's really complicated
    Try spending more than an hour studying the material before bouncing back with your "feed me" with food already chewed shtick.

    implementing square root function-one-hour-png

    That's being generous.
    Between my post, your notification, your reading and your response, maybe you just looked at it and gave up on the spot.

    You'll never achieve anything worthwhile if this is how quickly you throw in the towel.
    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.

  9. #9
    Registered User
    Join Date
    Nov 2018
    Location
    Amberg in upper palatinate, Bavaria
    Posts
    66
    Take a look to:
    YouTube

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-19-2020, 05:50 AM
  2. Square root function compiles but doesn't work
    By SupermanC in forum C Programming
    Replies: 1
    Last Post: 12-05-2013, 07:45 PM
  3. Making my own square root function
    By Alexthunder in forum C++ Programming
    Replies: 2
    Last Post: 02-02-2006, 07:36 PM
  4. square root
    By Noobie in forum C++ Programming
    Replies: 8
    Last Post: 02-18-2003, 11:01 AM
  5. square root function
    By Unregistered in forum C Programming
    Replies: 8
    Last Post: 05-19-2002, 03:11 AM

Tags for this Thread