xxxxxxxxxx
Formula:
(-b±√(b²-4ac))/(2a)
general form:
ax^2 + bx + c = 0
x^2 + bx + c = 0
some of the other hidden forms:
x^2 = bx - c (quadriatic after transposition)
c/bx+d = x (where you end up with a quadriatic after cross multiplication)
xxxxxxxxxx
(-b-sqrt(b**2-4*a*c))/(2*a)
(-b+sqrt(b**2-4*a*c))/(2*a)
If that doesn't work,
((0-b)-sqrt(b**2-4*a*c))/(2*a)
((0-b)+sqrt(b**2-4*a*c))/(2*a)
Quadratic Equation are equations where the highest power of the variable (usually x) is 2, hence the word Quadratic Equations
The standard form of Quadratic Equations is as follows...
xxxxxxxxxx
ax^2 + bx + c = 0 where a ≠ 0
This is because, even with an equation such as x^2 = 5, you can always* change it to the standard form.
xxxxxxxxxx
x^2 = 5
x^2 - 5 = 0
x^2 - 5 + 0x = 0 ### 0 * x is 0 anyways so we can add that
x^2 + 0x - 5 = 0
1x^2 + 0x - 5 = 0 ### 1 * x^2 is x^2 so we can add that (no change)
There! We got 1x^2 + 0x - 5 = 0!
You can cross check it with the standard form and see its the same!
Did you wonder why "a" can't be zero in the standard form? Well look here.
xxxxxxxxxx
5x^2 + 10x + 20 = 0 # PERFECTLY NORMAL QUADRATIC EQUATION
0x^2 + 10x + 20 = 0 # changing "a" to 0
10x + 20 = 0
At first glance, one may not notice the issue but let me pin point the definition of Quadratic Equation...
"Quadratic Equation are equations where the highest power of the variable is 2"
The definition states the highest power of x should be 2 but in 10x + 20 = 0 the highest power is 1 (where is no power, there is 1) so this equation became a linear equation! so to prevent that is why "a" or the coefficient of "x^2" can't equal to 0 in a Quadratic Equation
thank u! <3
NOW GO LEARN
-----------------
* = take with a pinch of salt
xxxxxxxxxx
import math
def solve_quadratic(a, b, c):
# Calculate the discriminant
discriminant = b**2 - 4*a*c
# Check if the equation has complex roots
if discriminant < 0:
return "Complex Roots"
# Calculate the roots
root1 = (-b + math.sqrt(discriminant)) / (2*a)
root2 = (-b - math.sqrt(discriminant)) / (2*a)
# Return the roots
return root1, root2
# Example usage
a = 1
b = -5
c = 6
roots = solve_quadratic(a, b, c)
print("Roots:", roots)
xxxxxxxxxx
import math
def solve_quadratic_equation(a, b, c):
discriminant = b**2 - 4*a*c
if discriminant > 0:
# Two distinct real roots
root1 = (-b + math.sqrt(discriminant)) / (2*a)
root2 = (-b - math.sqrt(discriminant)) / (2*a)
return root1, root2
elif discriminant == 0:
# One real root
root = -b / (2*a)
return root
else:
# Complex roots
real_part = -b / (2*a)
imaginary_part = math.sqrt(abs(discriminant)) / (2*a)
root1 = complex(real_part, imaginary_part)
root2 = complex(real_part, -imaginary_part)
return root1, root2
# Example usage with coefficients a, b, and c
a = 1
b = -3
c = 2
roots = solve_quadratic_equation(a, b, c)
print("Roots:", roots)
xxxxxxxxxx
from cmath import sqrt as c_sqrt
from math import sqrt as m_sqrt
import tkinter as tk
# creates and runs an instance of the window
window = tk.Tk()
#makes the size of the widow
window.geometry("600x400")
#sets a title for the screen
window.title("intercode")
# creating a new label and adding a text to the window
new_label=tk.Label(window,text='enter a,b,c quadratic formula\n')
new_label.pack()
#creates a entrybox to add words to window
entry_label1=tk.Entry(window)
entry_label1.pack()
entry_label2=tk.Entry(window)
entry_label2.pack()
entry_label3=tk.Entry(window)
entry_label3.pack()
# defines results as string var
results= tk.StringVar(window)
#creating a results label
result_lable=tk.Label(window,textvariable=results)
result_lable.pack()
def callbackfunct():
a =entry_label1.get()
b =entry_label2.get()
c =entry_label3.get()
try:
a= float(a)
b= float(b)
c= float(c)
except ValueError:
results.set("\nEnter number.")
if (b**2-4*a*c) < 0:
minus = (-b-c_sqrt(b**2-4*a*c))/(2*a)
plus = (-b+c_sqrt(b**2-4*a*c))/(2*a)
else:
minus = (-b-m_sqrt(b**2-4*a*c))/(2*a)
plus = (-b+m_sqrt(b**2-4*a*c))/(2*a)
# deletes the text in the text box
entry_label1.delete(0,tk.END)
entry_label2.delete(0,tk.END)
entry_label3.delete(0,tk.END)
var = (f"'B+' {plus} , 'B-' {minus}")
results.set(var)
# creating a button with a command
buttonez = tk.Button(text="Submit", command=callbackfunct)
buttonez.pack()
window.mainloop()