Click to See Complete Forum and Search --> : [RESOLVED] Quadratic function
bagstoper
Apr 26th, 2008, 07:56 PM
i need to transform the quadratic function into a one line math problem so i can just stick in a, b, and c into 3 different text boxes and then press a button and calculate it based on what a, b, and c are.
i hope i posted this in the write place but if i didn't then can a mod please move it.
03myersd
Apr 27th, 2008, 03:10 AM
xa = (-b + Sqr(((b * b) - (4 * a * c)))) / (2 * a)
xb = (-b - Sqr(((b * b) - (4 * a * c)))) / (2 * a)
Its in 2 lines as you need to get the plus and the minus values of x.
Logophobic
Apr 27th, 2008, 11:16 AM
It's not always that simple. Specifically, if the discriminant (b2 - 4ac) is negative, you will get an error with the Sqr() function.
Dim a As Double, b As Double, c As Double, d As Double
Dim x1 As Double, x2 As Double
Dim realpart As Double, imaginarypart As Double
Dim message As String
' Insert code to:
' 1) get values for a, b, and c
' 2) ensure that a <> 0
d = b * b - 4 * a * c
If d = 0 Then
' There is one real solution:
x1 = -b / (a + a)
message = "x = " & CStr(x1)
ElseIf d > 0 Then
' There are two real solutions:
x1 = (-b + Sqr(d)) / (a + a)
x2 = (-b - Sqr(d)) / (a + a)
message = "x = " & CStr(x1) & vbCrLf & "x = " & CStr(x2)
Else ' d < 0
' There are two complex solutions:
realpart = -b / (a + a)
imaginarypart = Sqr(-d) / Abs(a + a)
message = "x = " & CStr(realpart) & " + " & CStr(imaginarypart) & "i" & vbCrLf
message = message & "x = " & CStr(realpart) & " - " & CStr(imaginarypart) & "i"
End If
MsgBox message
bagstoper
Apr 27th, 2008, 12:28 PM
Thank you logophobic with a little tweaking your code worked great.
Icyculyr
Apr 30th, 2008, 04:32 AM
Hi, I was just wondering if you could tell me what a quadratic function is for, and what it does?
Cheers
Icyculyr
NickThissen
Apr 30th, 2008, 07:12 AM
It tells you the solution(s) to a quadratic equation, in the form of:
ax^2 + bx + c = 0
03myersd
Apr 30th, 2008, 11:36 AM
The solutions are simply where it crosses the x-axis. Of course you get ones which don't cross the x-axis and in that case the discriminant (the Sqrt(b^2-4ac) part) is negative. And as you know you cant get the square root of a negative number. So in that case there are no solutions.
zaza
Apr 30th, 2008, 02:05 PM
And as you know you cant get the square root of a negative number. So in that case there are no solutions.
I'm sure you've heard of imaginary numbers, where i = sqrt(-1), and all the rest are multiples of i.....
"Complex numbers" is the general term, and they have the form a+ib. They can be used to describe the entire range of numbers on the complex plane.
NickThissen
Apr 30th, 2008, 02:14 PM
I'm sure he did too, but to be honest if somebody doesn't know what the quadratic function is used for, it's probably best not to confuse them with imaginary numbers just yet ;)
zaza
Apr 30th, 2008, 02:53 PM
I've often found it's better not to deliberately say something that isn't true, because it's surprising what people remember a year or two down the line and subsequently things can become very confusing. "But I thought I was told that there was no such thing as the square-root of -1...???"
Better to skirt about the issue than mislead.
Icyculyr
Apr 30th, 2008, 07:03 PM
Interesting :D
Cheers
Icyculyr
03myersd
May 1st, 2008, 01:21 AM
I'm sure you've heard of imaginary numbers, where i = sqrt(-1), and all the rest are multiples of i.....
"Complex numbers" is the general term, and they have the form a+ib. They can be used to describe the entire range of numbers on the complex plane.
Yeah I did but as NickThissen said, its very complex compared to the straight forward quadratic function.
jemidiah
May 1st, 2008, 02:59 AM
...its very complex...
Yay bad and probably unintentional puns!
On a more interesting note, there is no (sane...) solution of the order 5 polynomial. That is, for the equation
ax5+bx4+cx3+dx2+ex1+f = 0,
there is no simple equation like the Quadratic Equation which can solve it. There are, however, versions of the Quadratic Formula for the third and (IIRC) fourth order polynomials. If you're interested in that sort of thing, take or study Group Theory/Galois Theory someday :)
NickThissen
May 1st, 2008, 02:06 PM
I've often found it's better not to deliberately say something that isn't true, because it's surprising what people remember a year or two down the line and subsequently things can become very confusing. "But I thought I was told that there was no such thing as the square-root of -1...???"
Better to skirt about the issue than mislead.
True. However this is the way most students will learn about complex numbers. I can't imagine for example a basics math studybook explaining what a square root of a number is, before veering off into explaning what complex numbers are...
Most people will think that square roots of negative numbers don't exist, and for the problems they have to solve, they ofcourse don't need complex numbers.
People in middle school for example who are going to become sport teachers or something like that probably don't care nor need to know about complex numbers.
Once you start studying higher maths or physics or whatever you need complex numbers for, then you can be taught about the square root of negative numbers.
But I do agree that it's a bit 'wrong' to exclaim the fact that square roots of negative numbers don't exist.
Icyculyr
May 1st, 2008, 11:11 PM
Lol, this is probably stupid, I but I've always figured the square root of -9, would be 3.. as 9 is 3.. is that right?
I also wonder, how do you do those little one's, two's, three's, four's, and five's etc.. as in post #13
Cheers
Icyculyr
03myersd
May 2nd, 2008, 01:32 AM
Ive never done it properly but from what ive picked up the square root of -9 is 3i. I wouldn't mind knowing how to do the superscripts either.
NickThissen
May 2nd, 2008, 04:25 AM
The square root of -9 can never be 3 because of the definition of square roots.
If the square root of -9 would be 3, then 32 would be -9, which ofcourse it's not.
Also, because every real number squared (2) is positive, the square root of a negative number can never be a real number. (Real numbers are all numbers from - infinity to +infinity).
However, some time back (can't remember the date lol), someone (Euler?) believed it would be useful if we could define a number which square would be negative. That number became i and it's defined as: i2 = -1.
Therefore, sqrt(-1) = i.
And, sqrt(-9) = 3i.
Oh and superscript is done with (sup)..(/sup) (only then with [ ] )
Slightly offtopic, but here's proof that -1 = 1
We all know 1 = -1 * -1
We also know sqrt(1) = 1.
Because 1 = -1*-1 we can write:
1 = sqrt(1) = sqrt(-1*-1) = sqrt(-1) * sqrt(-1) = i * i = i2 = -1
^^
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.