01 / Introductory
First principles
Begin with a physical model, not a solver.
Write the system boundary, assumptions, units and unknowns before entering equations.
Solve searches for symbolic solutions; FindRoot searches numerically from a starting value and can return a local root.
NDSolve integrates differential equations and returns interpolation rules.
Wolfram Language uses == for equations, = for assignment and capitalized built-in names.
Clear old definitions when reusing a notebook.
In the following code numeric magnitudes use explicitly stated units rather than Quantity objects; mixing unit systems would silently change the model.
02 / Applied
Worked example
A mixer combines two mass flows at solute mass fractions 0.20 and 0.50 to produce 100 kg/h at fraction 0.35.
Total and solute balances give f1 = f2 = 50 kg/h.
For a separate isothermal constant-volume first-order batch, k = 0.20 min⁻¹ and CA0 = 2 mol/L.
FindRoot estimates the time to 80% conversion from exp(−kt) = 0.20.
NDSolve computes CA(t) over 0–20 min and Plot displays the result.
Independent algebra gives t = 8.047189562 min and CA(10) = 0.2706705665 mol/L.
These expected values were checked with independent arithmetic and the analytic exponential solution; Mathematica itself was not executed for this article.
Mixer: F1 + F2 = Fout; F1 x1 + F2 x2 = Fout xout Batch: dCA/dt = −k CA; CA(t) = CA0 exp(−kt) CA(10 min) = 0.2706705665 mol/L; t80% = 8.047189562 min
| Parameter | Value | Unit |
|---|---|---|
| f1 | 50 | kg/h |
| f2 | 50 | kg/h |
| t (X = 0.80) | 8.047189562 | min |
| CA (t = 10 min) | 0.2706705665 | mol/L |
ClearAll["Global`*"];
(* Flows: kg/h; mass fractions dimensionless *)
Solve[{f1 + f2 == 100, 0.20 f1 + 0.50 f2 == 35}, {f1, f2}]
(* k: 1/min; t: min; concentration: mol/L *)
k = 0.20; ca0 = 2.0;
FindRoot[Exp[-k t] == 0.20, {t, 8}]
sol = NDSolve[{ca'[t] == -k ca[t], ca[0] == ca0}, ca, {t, 0, 20}];
ca[10] /. First[sol]
Plot[Evaluate[ca[t] /. First[sol]], {t, 0, 20},
AxesLabel -> {"t (min)", "CA (mol/L)"}, PlotRange -> All]03 / Advanced
Engineering decisions
Check residuals and physical feasibility after every solve: positive flow, 0≤X≤1, conserved mass and consistent units.
Try multiple starting values for nonlinear roots and inspect the graph; one successful FindRoot call does not establish uniqueness.
For coupled thermal and kinetic ODEs, stiffness and scaling can matter; refine accuracy and compare results rather than trusting default tolerances.
Compare the numerical batch solution with the analytic exponential and record parameters beside the plot.
Replace ideal assumptions only when reliable thermodynamic and kinetic data exist.
The copied code is a learning example, not an equipment safety or operating model.




Comments
There are no approved comments yet.
Without publication permission, your comment stays in your account.
Sign in by SMS to submit a comment.