Loading W Code...
5
Topics
Level 0
Foundation
🇮🇳 Indian Context
SIP investments, IPL scores, and student marks as real-world examples!
Foundation
import numpy as np
# LINEAR EQUATIONS
print("=" * 55)
print("SOLVING EQUATIONS")
print("=" * 55)
# Solve ax + b = 0
a, b = 3, -9
x = -b / a
print(f"\n1. Linear: {a}x + ({b}) = 0")
print(f" Solution: x = {x}")
# QUADRATIC EQUATIONS
# Example: Cost function J(w) = w² - 6w + 8
a_q, b_q, c_q = 1, -6, 8
discriminant = b_q**2 - 4*a_q*c_q
x1 = (-b_q + np.sqrt(discriminant)) / (2*a_q)
x2 = (-b_q - np.sqrt(discriminant)) / (2*a_q)
print(f"\n2. Quadratic: w² - 6w + 8 = 0")
print(f" Discriminant = {discriminant}")
print(f" Roots: w = {x1}, w = {x2}")
print(f" Minimum at w = {-b_q/(2*a_q)} (vertex formula)")
# Verify with numpy
roots = np.roots([a_q, b_q, c_q])
print(f" NumPy verification: {roots}")
# INEQUALITIES IN ML
print(f"\n3. Inequality Checks:")
learning_rate = 0.01
probability = 0.85
print(f" α = {learning_rate} > 0? {learning_rate > 0} ✓")
print(f" 0 ≤ P = {probability} ≤ 1? {0 <= probability <= 1} ✓")
# Indian Example: SIP Returns equation
print(f"\n📊 Indian Example: SIP Investment")
monthly_sip = 5000 # ₹5000/month
annual_rate = 0.12 # 12% p.a.
months = 36 # 3 years
# Future Value = P × [((1 + r)^n - 1) / r] × (1 + r)
r = annual_rate / 12
fv = monthly_sip * (((1 + r)**months - 1) / r) * (1 + r)
print(f" Monthly SIP: ₹{monthly_sip}")
print(f" After {months} months at {annual_rate*100}% p.a.")
print(f" Future Value: ₹{fv:,.0f}")