5.4.20 · D3 · HinglishScientific Computing (Python)

Worked examplesSymPy — symbolic algebra, calculus, ODE solving

3,038 words14 min read↑ Read in English

5.4.20 · D3 · Coding › Scientific Computing (Python) › SymPy — symbolic algebra, calculus, ODE solving

Yeh page parent SymPy note ke tools assume karta hai. Agar koi symbol unfamiliar lage, toh use use karne se pehle neeche define kiya gaya hai.


Scenario matrix

Har row ko padhho "is topic se banti ek situation" ki tarah, aur cell ko padhho "woh twist jo ise apna alag case banati hai."

# Category Specific case (twist) Worked in
A Solving Quadratic with two real roots Ex 1
B Solving Quadratic with complex roots (discriminant < 0) Ex 2
C Solving Degenerate equation: no solution / infinitely many Ex 3
D Calculus Derivative limit se recover kiya (first principles) Ex 4
E Calculus Definite integral jo exact rational deta hai vs decimal Ex 5
F Calculus Ek obvious nahi wala limit (0/0 form) Ex 6
G ODE Second-order, complex characteristic roots (oscillation) Ex 7
H ODE First-order with initial condition (real-world growth word problem) Ex 8
I Traps Exam twist: == vs true equality, aur solve ka output padhna Ex 9

Har woh symbol jo hum use karte hain — solve, diff, limit, integrate, dsolve, discriminant, I — woh usi waqt explain hoga jab woh pehli baar aayega.


Ex 1 — Cell A: quadratic, two real roots


Ex 2 — Cell B: quadratic, complex roots

Yahan twist hai discriminant. ke liye, discriminant hai — quadratic formula mein square root ke andar wala number. Yeh ek sawaal ka jawab deta hai: "kya roots real hain?" Agar yeh negative hai, toh ek negative number ka square root aata hai, aur SymPy ise symbol se likhta hai, jiska matlab hai (imaginary unit).


Ex 3 — Cell C: degenerate equations

Twist yeh hai: kabhi kabhi koi equation sach mein quadratic nahi hoti, ya uske koi ya infinite solutions hote hain. Tumhe empty list [] aur "hamesha true" wala case pehchanna hoga.


Ex 4 — Cell D: derivative from the limit

Yahan tool hai limit. Ek derivative ki instantaneous steepness measure karta hai; yeh ek limit ke roop mein define hota hai:

Yeh fraction do nearby points se guzarne wali line ki slope hai; hum gap ko zero tak squeeze karte hain taaki us point par slope mile. Dekho Limits and the definition of the derivative.

Figure — SymPy — symbolic algebra, calculus, ODE solving

Ex 5 — Cell E: exact rational vs decimal integral

Ek integral curve ke neeche se tak signed area hai. Twist yeh hai: SymPy ise exact (ek fraction ke roop mein) rakhta hai, aur tum choose karte ho kab decimal mein collapse karna hai .evalf() se.


Ex 6 — Cell F: obvious nahi wala limit (0/0)

Twist yeh hai: target value plug karne par milta hai, jo direct substitution se undefined hai. Isliye hi limit tool exist karta hai — yeh woh value dhundta hai jisko expression approach karta hai, chahe wahan directly evaluate na ho sake. Deeper "why" ke liye dekho Taylor and Maclaurin Series.


Ex 7 — Cell G: second-order ODE, oscillating solution

Ek ODE (ordinary differential equation) ek function ko uske derivatives se link karta hai; ise solve karne ka matlab hai function dhundhna, koi number nahi. dsolve tool hai. Twist yahan yeh hai: characteristic roots complex hain, jo oscillation () encode karte hain. Dekho Ordinary Differential Equations — characteristic equation method.

Figure — SymPy — symbolic algebra, calculus, ODE solving

Ex 8 — Cell H: first-order ODE with an initial condition (word problem)


Ex 9 — Cell I: exam twist — == aur solve output padhna


Active Recall

Recall Agar quadratic ka discriminant negative ho, toh

solve kya return karta hai aur kyun? Ek complex-conjugate pair jaise 2 ± 3*I, kyunki imaginary unit produce karta hai.

Recall

solve(...) ne [] diya. Kya yeh error hai? Nahi — [] ka matlab hai "koi solution exist nahi karta," ek valid mathematical answer (jaise ).

Recall

compute kyun karte hain, substitute karne ki jagah? Direct substitution indeterminate deta hai; limit woh value dhundta hai jisko expression approach karta hai ().

Recall Complex characteristic roots

kis tarah ke ODE solution mein badte hain? Oscillations: (frequency ).

Recall

ka answer 20*exp(x/2) kyun hai? "Rate ∝ size" → exponential; exponent set karta hai, aur constant fix karta hai.

Connections

  • Limits and the definition of the derivative (Ex 4, Ex 6)
  • Taylor and Maclaurin Series ( kyun)
  • Ordinary Differential Equations — characteristic equation method (Ex 7, Ex 8)
  • Lambdify — bridging SymPy to NumPy for plotting (in symbolic answers ko curves mein badlo)
  • NumPy — numerical arrays (floats vs upar ke exact rationals)
solve mein negative discriminant kya produce karta hai?
I (√−1) use karte hue ek complex-conjugate root pair.
Jab koi solution exist na kare toh solve kya return karta hai?
Ek empty list [].
x³ ka derivative first principles se kaise nikaalte hain?
limit(((x+h)**3 - x**3)/h, h, 0)3*x**2.
integrate(x**2+1,(x,0,2)) ki value?
14/3 (exact rational).
limit(sin(x)/x, x, 0) ki value?
1.
y''+9y=0 ka solution?
C1*sin(3*x)+C2*cos(3*x).
y'=y/2 with y(0)=20 ka solution?
20*exp(x/2).
(x+2)**2 == x**2+4*x+4 False kyun deta hai?
== structural identity test karta hai, math equality nahi; simplify(a-b)==0 use karo.