Hướng dẫn quadratic equation python - phương trình bậc hai python
Đưa ra một phương trình bậc hai, nhiệm vụ là giải phương trình hoặc tìm ra rễ của phương trình. Hình thức tiêu chuẩn của phương trình bậc hai là $$ AX^2 + BX + C = 0 $$ trong đó, $ a, b $, và $ c $ là số và số thực và cũng $ a \ ne 0 $ 0. Nếu $ a $ bằng $ 0 $, phương trình đó không hợp lệ phương trình bậc hai. Xem thêm: Hướng dẫn lập trình Python - Hướng dẫn Python Sử dụng công thức bậc hai dưới đây, chúng ta có thể tìm thấy gốc của phương trình bậc hai. Đặt $ \ delta = b^2-4ac $, sau đó: Đầu tiên, chúng ta phải tính toán phân biệt đối xử và sau đó tìm hai giải pháp của phương trình bậc hai bằng cách sử dụng & nbsp; ____ 11 & nbsp; mô -đun. # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input() Hình thức tiêu chuẩn của phương trình bậc hai là: ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 0 Các giải pháp của phương trình bậc hai này được đưa ra bởi: (-b ± (b ** 2 - 4 * a * c) ** 0.5) / (2 * a) Mã nguồn
Đầu ra Enter a: 1 Enter b: 5 Enter c: 6 The solutions are (-3+0j) and (-2+0j) Chúng tôi đã nhập mô -đun # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()1 để thực hiện căn bậc hai phức tạp. Đầu tiên, chúng tôi tính toán phân biệt đối xử và sau đó tìm hai giải pháp của phương trình bậc hai. Bạn có thể thay đổi giá trị của A, B và C trong chương trình trên và kiểm tra chương trình này. Đưa ra một phương trình bậc hai, nhiệm vụ là giải phương trình hoặc tìm ra rễ của phương trình. Dạng tiêu chuẩn của phương trình bậc hai là - ax2 + bx + c where, a, b, and c are coefficient and real numbers and also a ≠ 0. If a is equal to 0 that equation is not valid quadratic equation. Examples: Input :a = 1, b = 2, c = 1 Output : Roots are real and same -1.0 Input :a = 2, b = 2, c = 1 Output : Roots are complex -0.5 + i 2.0 -0.5 - i 2.0 Input :a = 1, b = 10, c = -24 Output : Roots are real and different 2.0 -12.0 Phương pháp 1: Sử dụng công thức trực tiếp Using the direct formula Sử dụng công thức bậc hai dưới đây, chúng ta có thể tìm thấy gốc của phương trình bậc hai. Đặt $ \ delta = b^2-4ac $, sau đó: If b*b < 4*a*c, then roots are complex (not real). For example roots of x2 + x + 1, roots are -0.5 + i1.73205 and -0.5 - i1.73205 If b*b == 4*a*c, then roots are real and both roots are same. For example, roots of x2 - 2x + 1 are 1 and 1 If b*b > 4*a*c, then roots are real and different. For example, roots of x2 - 7x - 12 are 3 and 4 Nếu $ b^2 - 4ac Nếu $ b^2-4ac = 0 $, thì rễ là có thật và cả hai gốc đều giống nhau $ x = \ frac {-b} {2a} $. Nếu $ b^2-4ac> 0 $, thì rễ là có thật và khác nhau $$ x = \ frac {-b \ pm \ sqrt {b^2-4ac}} {2a}. $$ $$ 2. Python giải phương trình bậc hai bằng mô -đun toán học phức tạp Đầu tiên, chúng ta phải tính toán phân biệt đối xử và sau đó tìm hai giải pháp của phương trình bậc hai bằng cách sử dụng & nbsp; ____ 11 & nbsp; mô -đun. 3 4 5 6 7# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()1 Mô -đun - Các hàm toán học cho các số phức - & nbsp; cung cấp quyền truy cập vào các hàm toán học cho các số phức. Các hàm trong mô-đun này chấp nhận số nguyên, số dấu phẩy động hoặc số phức là đối số. Họ cũng sẽ chấp nhận bất kỳ đối tượng Python nào có phương thức # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()3 hoặc # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()4: các phương pháp này được sử dụng để chuyển đổi đối tượng thành số điểm phức tạp hoặc nổi, và sau đó chức năng được áp dụng cho kết quả chuyển đổi. Hình thức tiêu chuẩn của phương trình bậc hai là: Các giải pháp của phương trình bậc hai này được đưa ra bởi: 3 4 5If b*b < 4*a*c, then roots are complex (not real). For example roots of x2 + x + 1, roots are -0.5 + i1.73205 and -0.5 - i1.73205 If b*b == 4*a*c, then roots are real and both roots are same. For example, roots of x2 - 2x + 1 are 1 and 1 If b*b > 4*a*c, then roots are real and different. For example, roots of x2 - 7x - 12 are 3 and 42 7Mã nguồn Đầu ra 3 4 5# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()00 7Chúng tôi đã nhập mô -đun # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()1 để thực hiện căn bậc hai phức tạp. Đầu tiên, chúng tôi tính toán phân biệt đối xử và sau đó tìm hai giải pháp của phương trình bậc hai. Bạn có thể thay đổi giá trị của A, B và C trong chương trình trên và kiểm tra chương trình này. Đưa ra một phương trình bậc hai, nhiệm vụ là giải phương trình hoặc tìm ra rễ của phương trình. Dạng tiêu chuẩn của phương trình bậc hai là - Phương pháp 1: Sử dụng công thức trực tiếp Có những trường hợp quan trọng sau đây. # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()6 # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()7 3 4 5# Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()45 7real and different roots 2.0 -12.05 real and different roots 2.0 -12.06 # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()8 # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()9 Output: real and different roots 2.0 -12.0
ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 00 (-b ± (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)3 ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 02 (-b ± (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)5 (-b ± (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)6 (-b ± (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)7 ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 00 (-b ± (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)9 0 1 2Đưa ra một phương trình bậc hai, nhiệm vụ là giải phương trình hoặc tìm ra rễ của phương trình. Dạng tiêu chuẩn của phương trình bậc hai là - Phương pháp 1: Sử dụng công thức trực tiếp Có những trường hợp quan trọng sau đây. # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()6 # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()7 # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()8 # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()9 ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 00 ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 01 ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 02 ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 03 ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 04 ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 03__ 4 5ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 002 ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 003 4ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 005 4ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 007 Output: # Python program to find roots of quadratic equation import cmath # function for finding roots def equationroots(): a = float(input('Enter coefficient a: ')) while a == 0: print("Coefficient a can not equal 0") a = float(input('Enter coefficient a: ')) b = float(input('Enter coefficient b: ')) c = float(input('Enter coefficient c: ')) # calculating dcriminant using formula d = b * b - 4 * a * c if d == 0: print("Your equation has real and same roots:") print(-b / (2 * a)) # when dcriminant is not equal 0 else: print("Your equation has complex roots:") print(- b / (2 * a), " +", cmath.sqrt(d)) print(- b / (2 * a), " -", cmath.sqrt(d)) equationroots() input()0 |