5.4.20 · HinglishScientific Computing (Python)

SymPy — symbolic algebra, calculus, ODE solving

1,734 words8 min readRead in English

5.4.20 · Coding › Scientific Computing (Python)


1. Symbolic computation kya hai?

x, y = symbols('x y')        # create two symbols
expr = x**2 + 2*x + 1        # an expression tree, NOT a number

TREE KYU? Kyunki x**2 + 2*x + 1 ki abhi koi value nahi hai — SymPy structure store karta hai taaki baad mein isse factor karke bana sake.


2. Algebra: simplify, expand, factor, solve


3. Calculus from first principles


4. ODE solving — dsolve

Figure — SymPy — symbolic algebra, calculus, ODE solving

5. The 80/20 cheat-table

Goal Call Note
unknown banana x = symbols('x') assumptions ke liye positive=True etc. use karo
brackets kholna expand(e)
ulta karna factor(e)
saaf karna simplify(e) heuristic
plug in karna e.subs(x, v) exact
decimal lena e.evalf() / N(e)
derivative diff(f, x) / diff(f,x,2) order extra arg se
integral integrate(f, x) ya (x,a,b)
limit limit(f, x, 0)
equation solve karna solve(Eq(l,r), x)
ODE dsolve(Eq(...), y(x), ics=...) Function chahiye

Active Recall

Recall

symbols('x') kya deta hai aur sirf x = 5 kyun nahi? Ek unknown symbolic object jo algebra preserve karta hai. x=5 sab kuch numbers mein collapse kar deta hai, us structure ko destroy karke jo tum manipulate karna chahte the.

Recall

diff(x**2, x) scratch se sahi kaise confirm karoge? limit((( x+h)**2 - x**2)/h, h, 0)2*x, jo derivative ki limit definition se match karta hai.

Recall

(x+1)**2 == x**2+2*x+1 False kyun deta hai? == structural identity hai, math equality nahi. simplify(a-b)==0 use karo.

Recall

dsolve kya form return karta hai aur constants kaise fix karte hain? Ek general Eq(y(x), ...) C1, C2 ke saath; inhe pin karne ke liye ics={y(0): ...} supply karo.

Recall (Feynman, ek 12-saal ke bachche ko samjhao)

Normal calculators sirf numbers jaante hain — inhe √2 do aur yeh panic hokar 1.414... ban jaate hain. SymPy ek robot math teacher ki tarah hai jo "√2", "x", "π" symbols ko board par exactly likha rakhta hai aur wahi pencil rules follow karta hai jo tumne seekhe hain — brackets kholna, factor karna, differentiate karna — aur cheezein tabhi decimals mein badalta hai jab tum .evalf() se politely poochho. Toh yeh kabhi rounding se jhooth nahi bolta, aur tumhe ek formula deta hai jo tum padh sako.

Connections

  • NumPy — numerical arrays (numbers vs symbols: opposite philosophies)
  • Limits and the definition of the derivative
  • Taylor and Maclaurin Series
  • Ordinary Differential Equations — characteristic equation method
  • Lambdify — bridging SymPy to NumPy for plotting
SymPy kya manipulate karta hai jo NumPy nahi karta?
Exact symbolic objects (x, √2, π, 1/3) ko expression trees ki tarah, floats nahi.
Symbolic unknown x kaise banate hain?
x = symbols('x').
SymPy mein expand karo?
expand((x+1)**2)x**2 + 2*x + 1.
factor karo?
factor(x**2-5*x+6)(x-2)*(x-3).
solve karo?
solve(x**2-5*x+6, x)[2, 3].
(x+1)² mein x=√2 substitute karo?
((x+1)**2).subs(x, sqrt(2)), exact rehta hai.
d/dx(x²) ki limit definition compute karo?
limit(((x+h)**2-x**2)/h, h, 0)2*x.
x² ka 0 se 1 tak definite integral?
integrate(x**2,(x,0,1))1/3.
sin(x) ki order 6 tak Taylor series?
sin(x).series(x,0,6)x - x**3/6 + x**5/120 + O(x**6).
y''+y=0 solve karo?
dsolve(Eq(y(x).diff(x,2)+y(x),0), y(x))C1*sin(x)+C2*cos(x).
Equality check ke liye == reliable kyun nahi hai?
Yeh structural identity test karta hai; simplify(a-b)==0 ya a.equals(b) use karo.
Symbolic result se decimal kaise lein?
.evalf() ya N(expr).
dsolve mein initial condition y(0)=3 kaise apply karein?
ics={y(0): 3} pass karo.

Concept Map

contrasts with

built from

combine into

manipulated by

includes

sets eq to zero

swap symbol with

collapse to number

enables

contains

derived from

equals

Symbolic computation

Numerical math numpy

Symbol x unknown

Expression tree

Algebra ops

subs substitute value

evalf N to decimal

solve eq for x

Calculus

diff derivative

limit definition