• BK (unregistered)

    this beam comes first

  • DeLos (cs)

    I was so close to being first. I suppose instead of reading the article I should have just made a guess at what it was about and see if my comment stuck or was removed.

  • SE (unregistered)

    No such thing as a W4x10.

  • Satanicpuppy (cs)

    Heh. Root finding launched me to cult hero status in college, as I managed to be the first person to program my graphing calculator to calculate roots via Newton's Method while showing the work. Made a tedious test question the work of seconds.

    Sure it was cheating, but I was a CS major, and I felt it was "better" for my career to be able to hack together the code on my calculator than it was to actually be able to do the math.

  • skztr (unregistered)

    Real wtf is the salesperson not responding with "That feature is in the latest version, I can bring that in for you tomorrow if you like". Almost makes me want to work for that vendor.

  • EJ_ (cs) in reply to Satanicpuppy
    Satanicpuppy:
    Heh. Root finding launched me to cult hero status in college, as I managed to be the first person to program my graphing calculator to calculate roots via Newton's Method while showing the work. Made a tedious test question the work of seconds.

    Sure it was cheating, but I was a CS major, and I felt it was "better" for my career to be able to hack together the code on my calculator than it was to actually be able to do the math.

    Haha, I loved doing this too. The teachers would proclaim "show your work!" so we wouldn't just let the calculators do it for us. I'd write a little application to show me what my work would have been had I done it out :) I never shared with anybody though... probably would have been a good way to make some friends looking back...

  • Satanicpuppy (cs)
    TopCod3r (Deleted as Troll):
    It is obvious the submitter of this story is not a PE (Professional Engineer). There is a major liability (legal) with the program recommending beam choices for a bridge. The only way to avoid this is to make the engineer suggest the beam, and only have the program tell whether it meets specifications or not.

    I don't see how that follows. If the engineer wants a list of beams that meet X criteria, and the program spits out an accurate list, then all is well. If the program cannot be trusted to accurately judge whether or not a beam meets specified criteria, then it's just as invalid whether its talking about one beam, or one-hundred beams.

    That's like saying it's the calculator's fault that the engineer made a math error. Regardless of the tools he uses, it's still his responsibility. I remember a case where the engineer was held responsible for a design decision that the contractors made without consulting him: the court decided that he should damn well have supervised.

  • Herman (unregistered)

    It's important not to let your computer calculate too much you know.

    It might take more than a second and that's an awful waste of time.

  • gabba (cs)

    Heh. This was possibly the best javascript-based introduction to non-linear minimization I have ever read.

  • GettinSadda (cs)

    So, the root problem solved like this would be:

    function rootGuess()
    {
      var numbr = prompt('What number do you want the Square Root of?',5),
          guess = prompt('OK, what do you *think* the Square Root of ' + numbr + ' is?',2);
      if (isNaN(parseFloat(numbr)) || isNaN(parseFloat(guess))) return;
    
      if ((guess * guess) == numbr) { 
        alert('Correct - the Square Root of ' + numbr + ' is ' + guess);
      } else {
        alert('Wrong - the Square Root of ' + numbr + ' is NOT ' + guess);
      }
    }

    Brillant!

  • JD (unregistered)
    Satanicpuppy:
    Heh. Root finding launched me to cult hero status in college, as I managed to be the first person to program my graphing calculator to calculate roots via Newton's Method while showing the work. Made a tedious test question the work of seconds.

    Sure it was cheating, but I was a CS major, and I felt it was "better" for my career to be able to hack together the code on my calculator than it was to actually be able to do the math.

    Finally, a voice of reason. I'm entirely with you my friend; as a CS student who hated maths I also found it a great deal more beneficial to program maths solutions on my graphical calculator than to figure them out by hand. This was many years ago now and since then, I've re-written (in production apps) plenty of the logic that I originally implemented on my calculator. In contrast, I've never had to work out any of those sums by hand at any time in my programming career. So with the power of hindsight I can say with absolute certainty that it was better from an educational standpoint to "cheat" with my calculator than to "do it properly". QED.

    Unfortunately, I don't really have anything relevant to note about today's post. So I'm just going to say thanks for the interactive Javascript root finder - that defnitely added a certain something to the tale for me.

  • lindee (unregistered)

    the real wtf is that parseFloat returns a new number. your function should be called terribleBabylonianGuessPlusStringConcatenation

    Note from Alex: Whoops, my bad: the "interactive" babylonianGuess() script has now been fixed. Score one for CDD (Community Driven Development).

  • Graham Stewart (unregistered)

    Hmm... the javascript root finder doesn't do so well with finding the root of negative numbers. :)

  • TopCod3rFan (unregistered)

    I'd like to reiterate my hope that one day we can sticky friends' posts as something to blue-ify for the main page.

  • bjolling (cs)
    nitehawk:
    SE:
    "The only way to avoid this is to make the engineer suggest the beam, and only have the program tell whether it meets specifications or not."

    No, you're wrong.

    It's TopCod3r, of course he is.

    Actually when I did my internship at a construction firm, I had to determine the dimensions of a small concrete bridge. Off course I inputted the parameters into a "finite elements" application and got the results. Then the head engineer asked me to re-calculate it manually using the apps output so that they would have the calculation on paper, in case something should need to be reviewed afterwards. (I suppose after my bridge collapsed...) TopCod3r isn't as wrong as usual :-)

  • Me (unregistered) in reply to TopCod3rFan
    TopCod3rFan:
    I'd like to reiterate my hope that one day we can sticky friends' posts as something to blue-ify for the main page.
    Whenever TopCod3r's posts get blue'd the entire comments section becomes nothing but an indulgence in delicious flame bait. Shame so many people round here need <sarcasm> tags.
  • Vince (unregistered)

    Try to guess 0, the answer is NaN !

  • Vince (unregistered) in reply to Vince

    Btw I don't understand why if I put 10 and guess 10 the first guess is 50.5 ?

  • lindee (unregistered) in reply to Vince
    lindee:
    the real wtf is that parseFloat returns a new number. your function should be called terribleBabylonianGuessPlusStringConcatenation

    babylonians couldn't parse floats... and neither can alex

  • Ilya Ehrenburg (unregistered) in reply to Vince
    Vince:
    Btw I don't understand why if I put 10 and guess 10 the first guess is 50.5 ?
    That's a nice little wtf in this site's code: originally, guess seems to be a string and so on entering the loop, the initial guess and the quotient numbr/guess are concatenated.
  • Yep (unregistered)

    I like how if you give the root finder script a decimal number for your guess, it only guesses NaN..

  • Square Root (unregistered) in reply to Graham Stewart
    Graham Stewart:
    Hmm... the javascript root finder doesn't do so well with finding the root of negative numbers. :)
    As Graham Stewart (unregistered) put it: That feature is in the latest version, I can bring that in for you tomorrow if you like.
  • Jack V (unregistered) in reply to Satanicpuppy
    Satanicpuppy:
    Sure it was cheating
    If you programmed that into the calculator in the first place it sounds to me like you _did_ do the math.

    OK, you were probably supposed to do it during the exam, rather than just once in your life, but so what :)

    (For some things, when you may need to have an intuitive grasp of them, doing them by hand is definitely useful. But AFAIK almost everyone only calculates roots by hand a few times when they first learn it.)

  • bucket (unregistered)

    A typical example of some 'manager' and it's crew designing an application from their point of view, without considering the real users, let alone actually having those real users help designing it or testing it. A shame, as this happens a lot and so many generic software applications could be so much better and so much more useful if people actually bothered to bring in the target audience to help with development (and if those people actually cared to help).

  • Thief^ (cs) in reply to Ilya Ehrenburg
    Ilya Ehrenburg:
    Vince:
    Btw I don't understand why if I put 10 and guess 10 the first guess is 50.5 ?
    That's a nice little wtf in this site's code: originally, guess seems to be a string and so on entering the loop, the initial guess and the quotient numbr/guess are concatenated.
    Yup, like this: function babylonianGuess() { var numbr = prompt('What number do you want the Square Root of?',5), // numbr = "10", also note the , instead of ; guess = prompt('OK, what do you *think* the Square Root of ' + numbr + ' is?',2); // guess = "10" if (isNaN(parseFloat(numbr)) || isNaN(parseFloat(guess))) return; // yay

    do { guess = 0.5 * (guess + numbr/guess); } // 0.5 * ("10" + "10"/"10") // = 0.5 * ("10" + 10/10) // = 0.5 * ("10" + 1) // = 0.5 * "101" // = 0.5 * 101 // = 50.5 while (confirm('Refine Further? ' + guess)); // ok do { guess = 0.5 * (guess + numbr/guess); } // 0.5 * (50.5 + "10"/50.5) // = 0.5 * (50.5 + 10/50.5) // basically it works as expected the second time onwards while (confirm('Refine Further? ' + guess)); }

  • Gorfblot (unregistered)

    I started writing a detailed explanation as to why the code gives a poor first approximation, as people are still asking.

    About 2 words into it, it occured to me- Did we just get trolled by Alex?

  • SomeCoder (unregistered) in reply to JD
    JD:
    Finally, a voice of reason. I'm entirely with you my friend; as a CS student who hated maths I also found it a great deal more beneficial to program maths solutions on my graphical calculator than to figure them out by hand. This was many years ago now and since then, I've re-written (in production apps) plenty of the logic that I originally implemented on my calculator. In contrast, I've never had to work out any of those sums by hand at any time in my programming career. So with the power of hindsight I can say with absolute certainty that it was better from an educational standpoint to "cheat" with my calculator than to "do it properly". QED.

    Unfortunately, I don't really have anything relevant to note about today's post. So I'm just going to say thanks for the interactive Javascript root finder - that defnitely added a certain something to the tale for me.

    The university I attended had a professor who not only wrote part of the STL for C++ but was a math major. As such, he offered a down to the metal, C++, math course. It was applying mathematical equations to programming, basically. We dealt with round off errors, IEEE floating point specs (we had to write a version of the entire IEEE spec for one assignment and had to actually manipulate the bits to do it) as well as applying Newton's method to get accurate roots, etc.

    Sounds like you guys might have enjoyed it. It had more direct application to programmers than a typical math class. It was one of the best classes I ever took there :)

  • Gabe (OP) (unregistered)
    TopCod3r:
    It is obvious the submitter of this story is not a PE (Professional Engineer). There is a major liability (legal) with the program recommending beam choices for a bridge.

    You know you're right - I'm not a PE - thats a US term and I work exclusively in Europe, mostly in England and we have different rules, regulations and qualifications. Alex has done a fair job of translating what I told him into Americanese, converting sizes and regulations etc, so cut him some slack.

    Why would there be a problem with a computers suggestion? Maths is maths, it doesn't matter if its done by a human or a pc. Potential for screw ups are -1) the program can't add up, in which case its the programmers liability, -2) The engineer makes a stupid choice, engineers can do that without needing to use a computer.

    Next point, why did we use GWBASIC over QUICKBASIC. Well GWBASIC was released in 83 and QUICKBASIC came out in 85, sorry but we didn't have a time machine.

  • Jack V (unregistered) in reply to Ilya Ehrenburg
    Ilya Ehrenburg:
    guess seems to be a string and so on entering the loop, the initial guess and the quotient numbr/guess are concatenated.

    That's what I eventually figured out. Easily done.

    Interestingly, because of the multiplication, it does work just fine if you start with an integer (just slightly longer because the first guess was off). And it gives NaN for negative inputs, which is probably correct :)

    (It would be more general if it correctly took complex square roots, and obviously more information is always potentially helpful, but there are many applications where NaN is much more meaningful than 3i; and if you want to treat a field more general than R+, you have to choose which square root to return, as there are two; and complex numbers is a natural place to stop, since square roots are again closed in C, but there are other fields where you can take roots so it's not the only correct answer, as it may appear :))

  • Sr Sw Eng (unregistered)

    TRWTF is thinking engineers cannot be good software developers. You know, as in Software Engineering.

  • TopCod3r (cs) in reply to Gabe (OP)
    Gabe (OP):
    Next point, why did we use GWBASIC over QUICKBASIC. Well GWBASIC was released in 83 and QUICKBASIC came out in 85, sorry but we didn't have a time machine.

    Hi Gabe, have you considered upgrading it from GWBASIC to QUICKBASIC?

  • Sr Sw Eng (unregistered)
    Comment held for moderation.
  • Worf (unregistered)

    Root finding - can't we optimize it a bit and just "guess" that the initial root is the number entered? (Or to optimize further, half the initial value, and then just test for 1).

    That way we have an automated square root function.

    The next challenge is figuring out what the stop condition is.

  • Rob (unregistered) in reply to Sr Sw Eng
    Sr Sw Eng:
    TRWTF is thinking engineers cannot be good software developers. You know, as in Software Engineering.
    At my place of work we have no "software developers"; all the developers have the official job title of "Software Engineer". This was done so that the company didn't have to employ any actual software engineers. We're never given any design to work to. If we ask for a design we get told "you're software engineers, it's your responsibility to design your work before you code it".
  • Yep (unregistered)
    Top Cod3r:
    lol top cod3r had to take the space out of his name

    All it took was someone registering his name for him to realize that maybe, just maybe, he ought to register a name if he plans to continue the regularly scheduled farce.

  • Jamface (unregistered)

    I want the square root of 2049.

    I think that it is 45.26588119

    Would I like to refine further than NaN?

    FAIL

  • SomeCoder (unregistered) in reply to Gabe (OP)
    Gabe (OP):
    TopCod3r:
    It is obvious the submitter of this story is not a PE (Professional Engineer). There is a major liability (legal) with the program recommending beam choices for a bridge.

    You know you're right - I'm not a PE - thats a US term and I work exclusively in Europe, mostly in England and we have different rules, regulations and qualifications. Alex has done a fair job of translating what I told him into Americanese, converting sizes and regulations etc, so cut him some slack.

    Why would there be a problem with a computers suggestion? Maths is maths, it doesn't matter if its done by a human or a pc. Potential for screw ups are -1) the program can't add up, in which case its the programmers liability, -2) The engineer makes a stupid choice, engineers can do that without needing to use a computer.

    Next point, why did we use GWBASIC over QUICKBASIC. Well GWBASIC was released in 83 and QUICKBASIC came out in 85, sorry but we didn't have a time machine.

    Gabe, this IS TopCod3r so please don't feed the trolls :)

  • Global Warmer (unregistered) in reply to Graham Stewart
    Graham Stewart:
    Hmm... the javascript root finder doesn't do so well with finding the root of negative numbers. :)

    Why don't you tell me what the square root of -25 is?

  • jmroth (cs)
    city building departments come to us for help in developing codes and standards for the computer age

    gimme teh codez :)

  • Marc B (unregistered)

    Why didn't he just write a script wrapped around the vendor's program to iteratively feed in each beam size and have it print out the ones that passed the test?

  • NotTheDroidYou'reLookingFor (unregistered)

    It's obvious the engineering firm was just too stubborn for their own good. All they needed to do was write a program to automatically input values into the forms to try every beam. When will people learn that fear of change is paralysis?

  • SomeCoder (unregistered) in reply to Global Warmer
    Global Warmer:
    Graham Stewart:
    Hmm... the javascript root finder doesn't do so well with finding the root of negative numbers. :)

    Why don't you tell me what the square root of -25 is?

    5i? :)

  • Topper Cod3r (unregistered) in reply to Gabe (OP)
    Gabe (OP):
    Next point, why did we use GWBASIC over QUICKBASIC. Well GWBASIC was released in 83 and QUICKBASIC came out in 85, sorry but we didn't have a time machine.

    Any decent engineer would have have known in 1983 that QUICKBASIC was in development, and would have designed programs using the beta version, as even it was vastly superior to GWBASIC. Obviously that means that your firm was clueless.

    Besides, TRWTF is that an engineer would use "83" and "85" to represent dates. Didn't you folks learn anything from that y2k fiasco?

  • El Bartho (unregistered) in reply to Global Warmer

    5i !?!

  • themagni (cs)
    TopCod3r:
    It is obvious the submitter of this story is not a PE (Professional Engineer). There is a major liability (legal) with the program recommending beam choices for a bridge. The only way to avoid this is to make the engineer suggest the beam, and only have the program tell whether it meets specifications or not.

    That's incorrect.

    I'm not a professional - yet. I'm an EIT, and they're wrapping up the paperwork next month.

    In order to accept computer calculations as valid for public safety and professional work, it is strongly suggested that you do three sets of calculations:

    1. By hand to get a rough idea. (e.g. It's somewhere between 70 and 80)
    2. By computer to confirm your results. (e.g. 75.1233)
    3. By a second program (not a second copy), ideally on a second computer to confirm the two previous results. (e.g. 74.9830)

    These recommendations are as a result of the roof collapse at a Save-on-Foods in Burnaby (Yes, it's called Cave-On-Foods by locals) due to a software glitch in the selection of the building materials. Luckily, nobody was killed. There was one injury (trampling) during the panicked customer egress.

    The investigation found that if the engineers had done a rough calculation, they would have found that the computer's answers were woefully inadequate. Thus the recommendation of rough calculations. The suggestion of the second computer is because computers are cheap.

  • ContraCorners (cs) in reply to Topper Cod3r
    Topper Cod3r:
    Gabe (OP):
    Next point, why did we use GWBASIC over QUICKBASIC. Well GWBASIC was released in 83 and QUICKBASIC came out in 85, sorry but we didn't have a time machine.

    Any decent engineer would have have known in 1983 that QUICKBASIC was in development, and would have designed programs using the beta version, as even it was vastly superior to GWBASIC. Obviously that means that your firm was clueless.

    Besides, TRWTF is that an engineer would use "83" and "85" to represent dates. Didn't you folks learn anything from that y2k fiasco?

    Laughing my a** off! Thank tc

  • Marvin the Martian (unregistered)

    This code would be better if it was more generic, to deal with decimal and negative numbers (you know, for when engineering goes imaginary).

    Please use generify-wand on the code.

  • Zap Brannigan (unregistered) in reply to SomeCoder
    SomeCoder:
    Global Warmer:
    Graham Stewart:
    Hmm... the javascript root finder doesn't do so well with finding the root of negative numbers. :)

    Why don't you tell me what the square root of -25 is?

    5i? :)

    5j?

    e^{j\pi} + 1 = 0 
    
  • Atlantys (unregistered) in reply to SomeCoder

    5j!

  • jDeepBeep (unregistered) in reply to SomeCoder

    For any positive real number b

    sqrt of negative b equals i sqrt of b

Leave a comment on “Sticking to the Method”

Log In or post as a guest

Replying to comment #:

« Return to Article