## Recommended Posts

Hi, I was going over some old tests of my math class from a few years back and saw quadradics, and couldn't remember crap about it so I sought to make a calculator for a better understanding. So far I have come up with this, which finds the vertex. Maybe if you'd like, that one person making the calculator in autoit could implement it. Hope you enjoy it.

EDIT: When I say X2 I mean X(squared)

```While 1
\$explain = MsgBox(4, "Quadratic Method", "Please leave out all variables (x's) and remember that A must always be present but if there is nothing inputted for B or C the computer will define it as a 0.  If you understand this click yes, if you don't click no for a brief explaination.", 5)
If \$explain = 6 Then
ExitLoop
ElseIf \$explain = 7 Then
MsgBox(0, "Rules of Calculator", "This calculators core runs on a simple formulae where if A or B > 0 then an X must be in place(X2 for variable A) So by adding strings of text it will result in a failure of calculation.  Also if you do not enter a value for A the calculations will be unsucessful because everything is dependant on A, but B and C if left blank will be assumed to 0 but please fill them in anyway. I hope this makes things easier!")
ExitLoop
EndIf
WEnd
#include <GuiConstants.au3>
GUICreate("Quadratic Calculator", 164, 285, (@DesktopWidth - 164) / 2, (@DesktopHeight - 285) / 2, \$WS_OVERLAPPEDWINDOW + \$WS_VISIBLE + \$WS_CLIPSIBLINGS)
\$pre = GUICtrlCreateLabel("This quadradic caluclator will use the factoring rules and methods to find the answer.", 10, 10, 150, 40)
\$al = GUICtrlCreateLabel("A equals", 10, 60, 60, 20)
\$a = GUICtrlCreateInput("", 80, 60, 70, 20)
\$bl = GUICtrlCreateLabel("B equals", 10, 90, 60, 20)
\$b = GUICtrlCreateInput("", 80, 90, 70, 20)
\$cl = GUICtrlCreateLabel("C equals", 10, 120, 60, 20)
\$c = GUICtrlCreateInput("", 80, 120, 70, 20)
\$calc = GUICtrlCreateButton("Calculate", 40, 160, 80, 20)
\$ans = GUICtrlCreateLabel("Answers will return here.", 10, 200, 150, 80)
GUISetState()
While 1
\$msg = GUIGetMsg()
If \$msg = \$GUI_EVENT_CLOSE Then
Exit
ElseIf \$msg = 10 Then
NumCheck()
EndIf
WEnd
Exit
\$x = -1* (\$b) / (2 * \$a)
\$y = \$a* (\$x * \$x) + \$b* (\$x) + \$c
GUICtrlSetData(\$ans, "The vertex is (" & \$x & "," & \$y & ")  [(x,y)]")
Func NumCheck()
;Check if numbers(To be worked out)
EndFunc  ;==>NumCheck```

AutoIt Smith

Edited by AutoIt Smith
##### Share on other sites

I don't know if this is usefull to anyone but i added a few more functions to your script, it now works out the points the curve crosses the x-axis (if any), and the y-axis as well as saying if the vertex is a maximum or minimum...

```While 1
\$explain = MsgBox(4, "Quadratic Method", "Please leave out all variables (x's) and remember that A must always be present but if there is nothing inputted for B or C the computer will define it as a 0.  If you understand this click yes, if you don't click no for a brief explaination.", 5)
If \$explain = 6 Then
ExitLoop
ElseIf \$explain = 7 Then
MsgBox(0, "Rules of Calculator", "This calculators core runs on a simple formulae where if A or B > 0 then an X must be in place(X2 for variable A) So by adding strings of text it will result in a failure of calculation.  Also if you do not enter a value for A the calculations will be unsucessful because everything is dependant on A, but B and C if left blank will be assumed to 0 but please fill them in anyway. I hope this makes things easier!")
ExitLoop
EndIf
WEnd
#include <GuiConstants.au3>
GUICreate("Quadratic Calculator", 200, 285, (@DesktopWidth - 200) / 2, (@DesktopHeight - 285) / 2, \$WS_OVERLAPPEDWINDOW + \$WS_VISIBLE + \$WS_CLIPSIBLINGS)
\$pre = GUICtrlCreateLabel("This quadradic caluclator will use the factoring rules and methods to find the answer.", 10, 10, 150, 40)
\$al = GUICtrlCreateLabel("A equals", 10, 60, 60, 20)
\$ina = GUICtrlCreateInput("", 80, 60, 70, 20)
\$bl = GUICtrlCreateLabel("B equals", 10, 90, 60, 20)
\$inb = GUICtrlCreateInput("", 80, 90, 70, 20)
\$cl = GUICtrlCreateLabel("C equals", 10, 120, 60, 20)
\$inc = GUICtrlCreateInput("", 80, 120, 70, 20)
\$calc = GUICtrlCreateButton("Calculate", 40, 160, 80, 20)
\$ans = GUICtrlCreateLabel("Answers will return here.", 10, 200, 185, 80)
GUISetState()
While 1
\$msg = GUIGetMsg()
If \$msg = \$GUI_EVENT_CLOSE Then
Exit
ElseIf \$msg = 10 Then
NumCheck()
EndIf
WEnd
Exit
Func NumCheck()
If \$a = "" Then
msgbox(0, "Error!", "You must type in a value for A")
ElseIf \$a = 0 Then
msgbox(0, "Error!", "A cannot be 0")
Else
If \$b = "" Then \$b = 0
If \$c = "" Then \$c = 0
EndIf
EndFunc ;==>NumCheck
\$y = \$a*\$x*\$x + \$b*\$x +\$c
EndFunc

\$x1 = round(-1* (\$b) / (2 * \$a), 3)
If \$a > 0 Then \$maxmin = "minimum"
If \$a < 0 Then \$maxmin = "maximum"
\$det = \$b^2-4*\$a*\$c
Select
Case \$det = 0
\$xcross = "crosses the x-axis at the vertex (" & \$x1 & "," & \$y1 & ")"
Case \$det < 0
\$xcross = "does not cross the x-axis"
Case \$det > 0
\$xcross = "crosses the x-axis at (" & Round((-\$b+sqrt(\$det))/2*\$a, 3) &  ",0) and also at (" & Round((-\$b-sqrt(\$det))/2*\$a, 3) &  ",0)."
EndSelect
GUICtrlSetData(\$ans, "The vertex is (" & \$x1 & "," & \$y1 & ")  [(x,y)]" & @CRLF & "This vertex is a " & \$maxmin & "." & @CRLF & "The curve crosses the y-axis at (0," & \$c & ")." & @CRLF & "The curve " & \$xcross)
##### Share on other sites

I had to write one in C a few weeks ago...I'll see if I can dig it up somewhere.

Edit: Here is the C Code

```#include <stdio.h>
#include <math.h>
float a, b, c, eq1, eq2, eq3, disc;
FILE *fmath;

main(){
fmath = fopen("math.dat", "r");
fscanf(fmath, "%f%f%f", &a, &b, &c);
fclose(fmath);
disc = (b*b-4*a*c);

if (a == 0 && b == 0) degen();
if (a == 0) ais0();
if (c == 0) cis0();
if (disc >= 0) discpos();
else discneg();
}

degen(){
printf("degenerate equation\n");
}

ais0(){
eq1 = -c/b;
printf("solution is x=%f\n", eq1);
}

cis0(){
eq2 = -b/a;
printf("solution is x = 0 AND x = %f\n", eq2);
}

discpos(){
eq1 = (-b+sqrt(disc))/(2*a);
eq2 = (-b-sqrt(disc))/(2*a);
printf("solution is x=%f and x=%f\n", eq1, eq2);
}

discneg(){
eq1 = sqrt(fabs(disc))/(2*a);
eq2 = -sqrt(fabs(disc))/(2*a);
eq3 = -b/(2*a);
printf("solution is x=%f+%fi and x=%f%fi\n", eq3, eq1, eq3, eq2);
}```
Edited by MSLx Fanboy

Writing AutoIt scripts since

`_DateAdd("d", -2, _NowCalcDate())`
##### Share on other sites

Griff you aren't following order of operations, and even my friend sitting next to me knows that!!! You cannot do this, 2 * \$x * \$x because is it x squared it must be, 2*(\$x * \$x) that way the numbers will square, I will fix up your calculator when I find some time if you want.

Much scripting love,

Max Gardner(AutoIt Smith)

##### Share on other sites

• 2 years later...

Griff you aren't following order of operations, and even my friend sitting next to me knows that!!! You cannot do this, 2 * \$x * \$x because is it x squared it must be, 2*(\$x * \$x) that way the numbers will square, I will fix up your calculator when I find some time if you want.

Much scripting love,

Max Gardner(AutoIt Smith)

Actually the order you multiply values does not matter, so long as you don't overflow or underflow. This is called commutativity. This same property applies to addition. Basically, 3 times 4 equals 4 times 3. Both are twelve. So putting the brackets around the \$x squaring really changes nothing, other than requiring an extra level of operations, which slow things down a little bit.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...