Bài 7
Đề bài: Giải phương trình mu dang a^x = b (a > 0, a != 1, b > 0).
x = log_a(b) = ln(b)/ln(a).
Giải 3 ví dụ:
1) 2^x = 32
2) 3^(2x-1) = 27
3) 5^x = 100 (nghiệm thực)
Ví dụ: nhập a và b cho bài toán a^x = b
Kết quả:
2^x = 32 => x = log_2(32) = 5.0
3^(2x-1) = 27 = 3^3 => 2x-1 = 3 => x = 2.0
5^x = 100 => x = log_5(100) = 2.861
Đăng nhập để giáo viên có thể giao bài và nhận bài nộp của bạn.
Câu trả lời
import math
print("=== Bai 1: 2^x = 32 ===")
a, b = 2, 32
x = math.log(b) / math.log(a)
print(f"x = log_{a}({b}) = {round(x, 6)}")
print(f"Kiem tra: {a}^{x} = {round(a**x, 4)}")
print("\n=== Bai 2: 3^(2x-1) = 27 ===")
# 3^(2x-1) = 3^3 => 2x-1 = 3 => x = 2
luy_thua = math.log(27) / math.log(3)
x = (luy_thua + 1) / 2
print(f"3^3 = 27 => 2x-1 = {luy_thua} => x = {x}")
print("\n=== Bai 3: 5^x = 100 ===")
a, b = 5, 100
x = math.log(b) / math.log(a)
print(f"x = log_{a}({b}) = {round(x, 6)}")
print(f"Kiem tra: {a}^{round(x,6)} = {round(a**x, 4)}")
print("\n=== Tong quat: Nhap a^x = b ===")
a = float(input("Nhap a: "))
b = float(input("Nhap b: "))
if a > 0 and a != 1 and b > 0:
x = math.log(b) / math.log(a)
print(f"Nghiem: x = {round(x, 6)}")
else:
print("Gia tri khong hop le")