Click to See Complete Forum and Search --> : Exponentials, Powers...
[Digital-X-Treme]
Mar 2nd, 2001, 04:35 PM
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.
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.
MsgBox CDbl(-3 ^ -0.000001)
I get the correct result??!?!?! Anyone got any ideas?
Later
Guv
Mar 3rd, 2001, 01:05 AM
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 following1 - 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.
[Digital-X-Treme]
Mar 3rd, 2001, 04:27 AM
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
Guv
Mar 3rd, 2001, 10:17 AM
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.(-3)^-.000001 = 0.99999890138338-0.000003141589202*iNote that the real part is approximately equal to (1/3)^.000001
[Digital-X-Treme]
Mar 3rd, 2001, 04:49 PM
Thanks for the explanation Guv. BTW, can u give me some information on this MathCad software you are using? Thanks.
Later
parksie
Mar 3rd, 2001, 05:40 PM
MathCad is a fairly nice piece of software, but it's hugely powerful and hugely expensive. :(
At the moment, though, I use Derive.
[Digital-X-Treme]
Mar 3rd, 2001, 05:56 PM
URLs... further information on this software???? ;)
parksie
Mar 3rd, 2001, 05:57 PM
www.mathcad.com is a good start :p
[Digital-X-Treme]
Mar 3rd, 2001, 06:13 PM
Always one step ahead... ;););) hehe
Later :)
parksie
Mar 3rd, 2001, 06:19 PM
Hehe...bye :)
Guv
Mar 3rd, 2001, 07:50 PM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.