Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: solve cubic equations

by no_slogan (Deacon)
on May 05, 2017 at 20:56 UTC ( #1189615=note: print w/replies, xml ) Need Help??


in reply to Re: solve cubic equations
in thread solve cubic equations

my \C = ( ( Δ1 + sqrt( Δ1 - 4 Δ0 + 0i) ) / 2 ).roots(3)[0];

Mathematically, your code is equivalent. (The arctan and cos are hidden inside roots.) Numerically, yours is potentially unstable. The first + in the line above might lose accuracy due to subtracting nearly-equal numbers. See Numerical Recipes, chapter 5.6. Unfortunately, sometimes we have to choose between code that looks nice and code that works.

The trouble with Perl 6 is that it's full of people who think it's a good idea to have a class called "Cool" which contains a hodgepodge of numerical and string-manipulation methods.

Replies are listed 'Best First'.
Re^3: solve cubic equations
by bduggan (Pilgrim) on May 11, 2017 at 00:08 UTC
    1. Yes, it's totally possible to optimize for accuracy, and yes, some situations call for that.
    2. Allomorphic typing is cool.
      1. Lots of things are cool, but you can't name them all "Cool" in your language.
      2. This post is the 9th hit on google for the phrase "allomorphic typing." Of the ones above it, 7 are about linguistics, and the other one says that term was briefly in use in computer science 26 years ago. You don't frighten me with your silly language behavior.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1189615]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2019-05-27 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (155 votes). Check out past polls.

    Notices?