Results 1 to 11 of 11

Thread: Exponentials, Powers...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Question

    Hi. I have come across the following error when trying to raise a number to the power of another number in VB. Here is my code.

    Code:
    Dim a As Double
    Dim b As Double
    Dim c As Double
    
    a = -3
    b = -0.000001
    'I get an error on the statement below
    c = a ^ b
    The error is Runtime error 5, invalid procedure call or argument. Why is this happening?

    When i do this.

    Code:
    MsgBox CDbl(-3 ^ -0.000001)
    I get the correct result??!?!?! Anyone got any ideas?

    Later
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Complex/Imaginary??

    Negative numbers raised to non-integer powers are either complex or imaginary.

    This would explain why your computational program causes an error. The result should be the following
    Code:
    1 - i*3.142E-6, where i = SquareRoot(-1)
    What value did your Msgbox program get? I would expect it to result in an error also.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Question Imaginary?!

    Thanks for the respons Guv. When i use the msgbox to evaluate the expression (-3^-0.00001), i get the following result:

    -0.9999890139

    I get the same result when i evaluate the expression on my two calculators as well. (Casio fx-9750G Power Graphic, and Casio fx-85WA) So i am assuming that the calculators are wrong, as they dont support imaginary numbers

    As i have not yet coded support for imaginary numbers, I will raise an error at this point in my program.

    Later
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  4. #4
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    HP48GX & MathCad7

    Digital-X-Treme: MathCad7 gave me the result in my previous post. When you mentioned your calculator, I tried my HP48GX. Lo & Behold! It also provided the same complex result.

    (1/3)^.000001 = .99999801388315 via MathCad7
    The above rounds to your MsgBox result.

    Note that X^ -n = (1 / X)^n

    The MsgBox calculation seems to have taken the positive power of the reciprocal.

    Repeated from previous post with more precision.
    Code:
    (-3)^-.000001 = 0.99999890138338-0.000003141589202*i
    Note that the real part is approximately equal to (1/3)^.000001
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Smile Nice

    Thanks for the explanation Guv. BTW, can u give me some information on this MathCad software you are using? Thanks.

    Later
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    MathCad is a fairly nice piece of software, but it's hugely powerful and hugely expensive.

    At the moment, though, I use Derive.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Question More info plz.

    URLs... further information on this software????
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    www.mathcad.com is a good start
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Aaaaaaah!

    Always one step ahead... hehe

    Later
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Hehe...bye
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    MathCad

    Digital-X-Treme: MathCad is an incredible software package.

    You can type in assignment statements to establish values of variables. Then almost any formula you type in will be evaluated. It works a bit like a spread sheet without the matrix like cell structure. Change values for variables and the formulae are recalculated.

    It will do complex arithmetic and will generate graphs of functions. It does a great job of formating formulae, making them like what you might see in a high class college math text. You can insert remarks anywhere you want. It will print your formulae and remarks, and would be great for doing homework or tutoring work.

    It has Pallete like menus (similar to floating toolbars) for basic trig and other functions, as well as a pallete like menu for Greek letters, which are commonly used in Math notation. You can even click on more complex items like a summation symbol and fill in the from & to values and a formula to be summed. It has Pi and e to about 15 places from one of the menus.

    My mathCad7 is a bit obsolete now.

    I have not used it, but I think it will do numerical integration if you give it the function and range.

    It is an expensive piece of software ($600 or more American, retail), but there might be a student version available cheap.

    I bought my original version (5 or 6) at a computer show for about $50.00 a few years ago. It was supposed to be bundled with a computer and educational software, but the vendor installed it on the computers he sold and then sold the CD's cheap without the manuals. It was user friendly and easy to hack. After registering it, I was given cheap upgrade offers and ended up with version 7 and a manual.

    If there are computer shows in your area, they are a great place to buy cheap software & hardware. Some of the software deals are incredible.

    If you can find a student version and qualify as a student, it might be worth buying. If I were more affluent, I would pay the retail price for the latest version or maybe find it at a 40-50% discount some where. Perhaps I will be lucky at the next computer show.

    To give you an idea of the cost of student versions: Mathematica (the premier application of this type) sells for close to $1000 American, but I bought a student version for $125.00. Unfortunately for me, it required proof of my being a student to get the password required for installation, so I gave it to my girl friend's grandson. If you find a student version and are not a student, you could obviously find a student to register it for you.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width