I have been told that you guys can solve about any math problem!
I think I have answered my own question on solving Fourth Degree Equations, but in the process, I need to find the Arc Cosine of a number. What is an ArcCosine and how do I find it? I am writing a program in VB .Net. (I don't have a good enough mind to figure it out on my own!)
Originally, I had these Equations:
VB .Net Code:
Me.lblFirst.Text = -b / (4 * a) _
- 1 / 2 * Math.Sqrt(b ^ 2 / (4 * a ^ 2) - 2 * c / _
(3 * a) + 2 ^ (1 / 3) * (c ^ 2 - 3 * b * d + 12 * a * f) / (3 * a * (2 * c ^ 3 - 9 * _
b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * (c ^ _
2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 _
* b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3)) + 1 / (3 * 2 ^ (1 / 3) * a) * (2 * c ^ _
3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * _
(c ^ 2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + _
27 * b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3)) _
- 1 / 2 * Math.Sqrt(b ^ 2 / (2 * _
a ^ 2) - 4 * c / (3 * a) - 2 ^ (1 / 3) * (c ^ 2 - 3 * b * d + 12 * a * f) / (3 * a * _
(2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + _
Math.Sqrt(-4 * (c ^ 2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + _
27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3)) - 1 / (3 * 2 ^ (1 / _
3) * a) * (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * _
f + Math.Sqrt(-4 * (c ^ 2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * _
d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3) _
- (-b ^ 3 / a ^ _
3 + 4 * b * c / a ^ 2 - 8 * d / a) / (4 * Math.Sqrt(b ^ 2 / (4 * a ^ 2) - 2 * c / (3 * _
a) + 2 ^ (1 / 3) * (c ^ 2 - 3 * b * d + 12 * a * f) / (3 * a * ((2 * c ^ 3 - 9 * b * _
c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * (c ^ 2 - 3 * _
b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * _
f - 72 * a * c * f) ^ 2))) ^ (1 / 3)) + 1 / (3 * 2 ^ (1 / 3) * a) * (2 * c ^ 3 - 9 * _
b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * (c ^ 2 - _
3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ _
2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3))))
Me.lblSecond.Text = -b / (4 * a) _
- 1 / 2 * Math.Sqrt(b ^ 2 / (4 * a ^ 2) - 2 * c / _
(3 * a) + 2 ^ (1 / 3) * (c ^ 2 - 3 * b * d + 12 * a * f) / (3 * a * (2 * c ^ 3 - 9 * _
b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * (c ^ _
2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 _
* b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3)) + 1 / (3 * 2 ^ (1 / 3) * a) * (2 * c ^ _
3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * _
(c ^ 2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + _
27 * b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3)) _
+ 1 / 2 * Math.Sqrt(b ^ 2 / (2 * _
a ^ 2) - 4 * c / (3 * a) - 2 ^ (1 / 3) * (c ^ 2 - 3 * b * d + 12 * a * f) / (3 * a * _
(2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + _
Math.Sqrt(-4 * (c ^ 2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + _
27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3)) - 1 / (3 * 2 ^ (1 / _
3) * a) * (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * _
f + Math.Sqrt(-4 * (c ^ 2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * _
d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3) _
- (-b ^ 3 / a ^ _
3 + 4 * b * c / a ^ 2 - 8 * d / a) / (4 * Math.Sqrt(b ^ 2 / (4 * a ^ 2) - 2 * c / (3 * _
a) + 2 ^ (1 / 3) * (c ^ 2 - 3 * b * d + 12 * a * f) / (3 * a * ((2 * c ^ 3 - 9 * b * _
c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * (c ^ 2 - 3 * _
b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * _
f - 72 * a * c * f) ^ 2))) ^ (1 / 3)) + 1 / (3 * 2 ^ (1 / 3) * a) * (2 * c ^ 3 - 9 * _
b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * (c ^ 2 - _
3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ _
2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3))))
Me.lblThird.Text = -b / (4 * a) _
+ 1 / 2 * Math.Sqrt(b ^ 2 / (4 * a ^ 2) - 2 * c / _
(3 * a) + 2 ^ (1 / 3) * (c ^ 2 - 3 * b * d + 12 * a * f) / (3 * a * (2 * c ^ 3 - 9 * _
b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * (c ^ _
2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 _
* b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3)) + 1 / (3 * 2 ^ (1 / 3) * a) * (2 * c ^ _
3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * _
(c ^ 2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + _
27 * b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3)) _
- 1 / 2 * Math.Sqrt(b ^ 2 / (2 * _
a ^ 2) - 4 * c / (3 * a) - 2 ^ (1 / 3) * (c ^ 2 - 3 * b * d + 12 * a * f) / (3 * a * _
(2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + _
Math.Sqrt(-4 * (c ^ 2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + _
27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3)) - 1 / (3 * 2 ^ (1 / _
3) * a) * (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * _
f + Math.Sqrt(-4 * (c ^ 2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * _
d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3) _
+ (-b ^ 3 / a ^ _
3 + 4 * b * c / a ^ 2 - 8 * d / a) / (4 * Math.Sqrt(b ^ 2 / (4 * a ^ 2) - 2 * c / (3 * _
a) + 2 ^ (1 / 3) * (c ^ 2 - 3 * b * d + 12 * a * f) / (3 * a * ((2 * c ^ 3 - 9 * b * _
c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * (c ^ 2 - 3 * _
b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * _
f - 72 * a * c * f) ^ 2))) ^ (1 / 3)) + 1 / (3 * 2 ^ (1 / 3) * a) * (2 * c ^ 3 - 9 * _
b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * (c ^ 2 - _
3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ _
2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3))))
Me.lblFourth.Text = -b / (4 * a) _
+ 1 / 2 * Math.Sqrt(b ^ 2 / (4 * a ^ 2) - 2 * c / _
(3 * a) + 2 ^ (1 / 3) * (c ^ 2 - 3 * b * d + 12 * a * f) / (3 * a * (2 * c ^ 3 - 9 * _
b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * (c ^ _
2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 _
* b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3)) + 1 / (3 * 2 ^ (1 / 3) * a) * (2 * c ^ _
3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * _
(c ^ 2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + _
27 * b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3)) _
+ 1 / 2 * Math.Sqrt(b ^ 2 / (2 * _
a ^ 2) - 4 * c / (3 * a) - 2 ^ (1 / 3) * (c ^ 2 - 3 * b * d + 12 * a * f) / (3 * a * _
(2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + _
Math.Sqrt(-4 * (c ^ 2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + _
27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3)) - 1 / (3 * 2 ^ (1 / _
3) * a) * (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * _
f + Math.Sqrt(-4 * (c ^ 2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * _
d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3) _
+ (-b ^ 3 / a ^ _
3 + 4 * b * c / a ^ 2 - 8 * d / a) / (4 * Math.Sqrt(b ^ 2 / (4 * a ^ 2) - 2 * c / (3 * _
a) + 2 ^ (1 / 3) * (c ^ 2 - 3 * b * d + 12 * a * f) / (3 * a * ((2 * c ^ 3 - 9 * b * _
c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * (c ^ 2 - 3 * _
b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * _
f - 72 * a * c * f) ^ 2))) ^ (1 / 3)) + 1 / (3 * 2 ^ (1 / 3) * a) * (2 * c ^ 3 - 9 * _
b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * (c ^ 2 - _
3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ _
2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3))))
This was a little to complicated for me. It also was returning "N/A" (meaning: "Not a Number"). Any suggestions?
Since then I have been using this method because the aforesaid was not working. Thus, my problem of finding the ArcCosine.
I don't really care HOW I find the roots of the equation. I just want to be able to do it.
Just to let you know, if you give me the method, I can put it into VB .Net. Don't feel obligated to program for me. It somebody does know VB, that would be great!
Wow. That's a long post! I thank you for reading this far!
VBNetDude - Thinking Programmatically By Silver Seal Software
Don't forget to mark your thread as "Resolved" using the Thread Tools menu on top. And don't forget to rate the answers that help you the most!
And if you cant, Im the truck that pointed him to the maths forum. So blame me. What can I say, Jemidiah does great work.
NicelyDone: The Visual Studio 2008 Newb
There are 10 types of people in this world...Those who know binary and those who don't.
*cough* Asimov *cough*
I used to be a pro at HTML...Wait, nooooo! Epic fail
Solving the quartic is hideous. My guess is that .NET doesn't natively support complex arithmetic, so that if your root is complex, you'll eventually take the square root of a negative number, which I suppose would throw a "not a number" exception. You could recast all of your formulas to use complex arithmetic, which would make them even more messy [unless .NET has operator overloading like C++]. You could also do a sort of "try-catch" block. If you get an imaginary root, it will error, and you can just output "(Complex)" or something, assuming you don't care about the complex solutions and some special cases. Also, this assumes that code is correct in the first place.
As I alluded to, the formulas you've listed don't have special cases. Try a quartic with a=0 (which is actually a cubic, since the leading term vanishes); you'll throw a divide by zero error. Less trivially, try a quartic with... [ (3 * a * (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f + Math.Sqrt(-4 * (c ^ 2 - 3 * b * d + 12 * a * f) ^ 3 + (2 * c ^ 3 - 9 * b * c * d + 27 * a * d ^ 2 + 27 * b ^ 2 * f - 72 * a * c * f) ^ 2)) ^ (1 / 3)) ] equal to zero, and you'll get another divide by zero error.
In any case, there are a number of ways to get inverse cosines:
Math.Acos (arc cosine) seems to have been built in to the .NET Framework since version 1.1 at least; perhaps you could use that.
The VB6 way of doing inverse trig functions was to use identities based off being able to do Atan (Atn), like "Acos(x) = 2 Atan(Sqrt(1-x^2)/(1+x))" [which needs to have a special case for x=-1 or you'll get a divide by 0 error]. Of course this requires Atan.
You can implement your own inverse cosine in a number of ways. There's always the Taylor Expansion (Maclaurin Expansion is more commonly used, but most people don't notice the difference). That probably doesn't converge very quickly, though.
You could use one of a large number of root finding methods to solve the equation (cos(x) - A = 0, A being your input to your Acos function), which would yield some X where cos(X) = A, i.e. where X = Acos(A). Newton's Method is popular and simple for root finding, especially for a function whose derivative is so well known (derivative of cos(x) is -sin(x), derivative of a constant is 0), though I question how quickly it would converge because of the oscillations of cos(x) and sin(x).
I'm sure there are other ways as well. I feel like fixed point iteration could be used somehow, but I can't see how. Hopefully one of the above is what you're looking for.
Edit: to more explicitly answer your question, an "arc cosine" is just an inverse cosine. Nothing more, nothing very special. It's probably an archaic term from navigation, though that's just a guess.
Last edited by jemidiah; Nov 21st, 2009 at 12:59 PM.
The time you enjoy wasting is not wasted time. Bertrand Russell
I work with VB6, not VB net. So I do not understand all those equations you have posted. (Am not sure I would understand even were they in VB6.)
However the question you asked about how to obtain the Arc(cos) of a value is interesting, and I have "played" with this.
You must understand that Arc(cos) becomes ambiguous after the range 0-180 degrees. Therefore I have restricted the displayed result hereunder to this angle range.
I attach (as a .zip) a VB6 program I have written which does this. You enter the Arc(cos) value, click the command and it brings up the angle in degrees.
The time taken, with my computer, is "negligible". The answer agrees with my scientific calculator to, in most cases tested, about 0.005 of a degree, or better. (I wonder which is the more accurate?).
The procedure used is one of 3 stage successive iteration. By using 3 stages of increasingly fine iteration, a successive approximation approach is achieved. The 3 stages avoid excessive wasteful stages of iteration calculations. It could still be bettered. See what you think.
Interesting question. I invite you to try the program and/or to read the code and let me know by return to this thread how it works for you.
You did not specify the accuracy to which you need the Arc(Cos).
FAO. Previous poster, I do not think that the use of "arc" refers to any marine consideration, but can not suggest better! When I learnt maths, we used the notation Cos-1 for Arc(cos). Maybe "Arc" comes from Greek? I only learnt Latin a long time ago, and then not too well.
camoore
Wales, UK
Last edited by camoore; Nov 25th, 2009 at 04:34 PM.
Reason: typo
That's an interesting way to evaluate ArcCos, though it's close to guess and check--it could take advantage of the smoothness of the cosine function, for instance. In VB6, you actually can use the Atn function to compute ArcCos's:
Code:
x = 0.4
MsgBox 2 * Atn(Sqr(1 - x ^ 2) / (1 + x))
As for the word "arc", it's somewhat useful in that you don't have to write cos^-1 (which might get confused with 1/cos). I don't know where the word came from.
The time you enjoy wasting is not wasted time. Bertrand Russell
.NET does have operator overloading, so somebody has probably made a complex number class.
I would suggest that you add the extra code to check for a value being negative before taking a square root, unless you do use a special type that will handle that situation correctly. After all, catching exceptions is about the slowest thing you can do.
jemidiah, Your code is a lot more simple than mine but I was not sure whether the OP. was using VB6 with its arc tan function.
My method of successive converging iteration is pretty simple, but not "rocket science". However if it works and is not too slow, then it is a solution. This approach can be applied to solving a lot of functions for which the inverse calculation is not readily available. I also use it, with variations, for extrapolation between points on experimentally derived data graphs.
The degree of agreement with my scientific calculator was not bad.
Is it not time for the OP. to respond to these replies and to mark the thread as Resolved if he (she) is satisfied?
camoore
Wales, UK
Last edited by camoore; Nov 26th, 2009 at 11:05 PM.
Reason: typo
Camoore, your method of "successive converging iteration" definitely works, and it applies in general to inverting many functions. Mostly, I meant that you can do your method faster. For instance, if the function is invertible, it's monotonic (always increasing or always decreasing). You can then use binary search to find which input gives you a particular value of the output--i.e. to find the inverse at a given point.
Ex:
Function is cosine, from 0 to pi. Target: inverse cosine of 1/32.
Step 1: Initial limits are 0 to pi; cos(0)=1, cos(pi)=-1, function is going down. Is inverse cosine of 1/32 in this range, 0 to pi? Yes, since -1 <= 1/32 <= 1. Continue.
Step 2: Calculate midpoint of previous limits, pi/2. cos(pi/2) = 0 <> 1/32. Since function is going down, inverse cosine must be in the left half of the previous limits, i.e. between 0 and pi/2.
Step 3: Repeat step 2 with limits 0 to pi/2 instead; we'll find the inverse cosine must be in the right half, between pi/4 and pi/2.
...
At each step we have a lower and upper bound for the value we want to find. Continue until the bounds are sufficiently close. This method generalizes to be significantly faster than the linear search you gave. For instance, it may take 20 iterations to get 10 digits with mine, while yours would take hundreds of iterations.
I agree, it's time for the OP to mark this resolved or ask another question .
The time you enjoy wasting is not wasted time. Bertrand Russell
Now that you mention that approach of yours, distant recollections of university maths come to mind - but while maths interested me I was never that good at it, but in my career as an electronic systems engineer always found a way round problems albeit as in this case in not too elegant a manner.
If speed of calculation is of the essence then your approach using less iterations is undoubtedly much better. But a good thing about computers is that they happily do thousands of boring repetitive things remarkably quickly. The OP. did not mention his need for speed. I found the time my machine took to do those sums very little. There was no perception of any calculatiog delay (but of course there must have been one).
An interesting problem. Now where has the OP. gone?
An interesting problem. Now where has the OP. gone?
That is an interesting problem. For some of you that don't have anything important going on (like Thanksgiving, or extra traveling...) I would appreciate a bit of understanding when my life does not revolve around VB Forums.
Thank-You all for helping.
camoore: I don't mind the computer being a bit slow for calculations, so speed doesn't matter. Since my Quartic program is quite extensive right now, I think I will go with jemidiah's way (.Net does indeed include Math.ACos), but I do appreciate the amount of work that you have put into this!
Again, much thanks to all who posted!
Last edited by VBNetDude; Nov 27th, 2009 at 05:06 PM.
VBNetDude - Thinking Programmatically By Silver Seal Software
Don't forget to mark your thread as "Resolved" using the Thread Tools menu on top. And don't forget to rate the answers that help you the most!
For some of you that don't have anything important going on (like Thanksgiving, or extra traveling...) I would appreciate a bit of understanding when my life does not revolve around VB Forums.
Sorry, I didn't mean to sound pushy. It simply was time for more feedback, that's all. I do actually have things going on, but the forums are one thing I read and respond to to relax, so I tend to check them often regardless . I'm curious, has your other thread been answered well?
The time you enjoy wasting is not wasted time. Bertrand Russell
Well, I am still working on it. I'm having a few issues. Some calculation error that I will probably post here.
I don't have the program with me, so I cannot say for sure. The program keeps spitting out values for x that don't actually work. I'm not quite sure what calculation error I am getting. Maybe I am supposed to use angles instead of radians for the output of Arc Cosine?? I don't know.
There is a guy I know here in town that took some sort of really high math: something with the name "Chaos". He suggested that an easier way would be to use symmetric division to solve. What would you recommend?
VBNetDude - Thinking Programmatically By Silver Seal Software
Don't forget to mark your thread as "Resolved" using the Thread Tools menu on top. And don't forget to rate the answers that help you the most!
If you are working in VB6, then the angle entered / returned MUST be in radians. In the program I wrote for you, I arranged for this to be converted to degrees, which as a navigation specialist, I tend to prefer. Hence the output of my demmo program was in degrees. It does not matter, of course, in what units a Cosine is entered, since a Cosine is a Cosine. ie. a numerical value between +1 and -1.
I am only VB6 experienced (and that only a bit) so can not comment upon the inputs / outputs of equivalent VBNet routines.
The essence of these replies to your post has been how to calculate ArcCos either by a direct formula (if the ArcTan function is available) or by various iterative methods.
I have already posted for you a program which finds ArcCos to reasonable accuracy.
If you have any difficulty in following its code (which is commented) please make a further post (or send a PM.). The Forum objective is always to solve the problem listed by the OP.
Symmetric division doesn't appear to mean anything (except in biology during cell division, apparently, looking at Google's top results). Perhaps he meant either symmetric polynomials or synthetic division.
Symmetric polynomials are unhelpful for actually finding roots, unless there's something I'm not aware of there. They have deep connections in Galois theory, which does consider roots of polynomial equations, but they're only a stepping stone to consider when a particular polynomial is solvable (in algebraic numbers). I'm betting he meant synthetic division.
Synthetic division is helpful in special cases only, and is (I would say) somewhat of a toy method for exposing students to polynomials, generalizations, and abstract thinking. You can only use synthetic division to solve a polynomial for its roots when you already know at least one root. You often are either given that other root in a problem statement, or you can graph the equation and guess--it's almost always +/- 2 or +/- 1 anyway, since if the root was messy you wouldn't be able to guess it from the picture.
Synthetic division does work with complex numbers, but it would seem to be almost completely unhelpful if the roots of your equation were all complex--which may happen with a 4th degree equation. To guess a root for use in synthetic division in this case, you would need two 3D graphs of the polynomial plotted against the real and complex parts of its input, with one plot being the real part of the output, the other being complex. In any case, for solving general 4th degree polynomials, synthetic division almost certainly won't help.
Now, to your problem. Most likely you've coded something incorrectly, or (there's always some chance of this) the site you used to get your method from is incorrect. I'd lean towards a coding error, since the site you linked looked to have done a careful job. Math.Acos does in fact give output in radians.
The page you linked requires you to implement a cubic equation solver--is that working? On the quartic equation calculator page, it lists intermediate values in the calculation, at the bottom of the page--do yours agree?
The time you enjoy wasting is not wasted time. Bertrand Russell