Mathematical and Computational FoundationsIntroduction and ContextArtificial intelligence in mechatronics is built on mathematical models of physical systems, measurements, uncertainty, and decision processes. A robot manipulator, autonomous vehicle, inspection station, or intelligent actuator produces data and operates within constraints. AI methods transform these data into estimates, predictions, classifications, or control actions. However, reliable implementation requires more than selecting a machine-learning library. Engineers must represent variables correctly, understand numerical conditioning, quantify uncertainty, formulate optimization problems, and assess whether computed results are physically meaningful. This chapter develops the foundations needed to model mechatronic systems and implement AI algorithms in Python or comparable engineering software. Linear algebra provides representations for vectors, matrices, coordinate transformations, and learned parameters. Calculus describes rates of change, sensitivity, and dynamic behavior. Probability and statistics provide tools for uncertainty and inference. Optimization supplies methods for fitting models and selecting actions. Numerical methods make these ideas computable on digital hardware. Learning ObjectivesBy the end of this chapter, students should be able to: - Represent mechatronic states, measurements, transformations, and datasets using vectors and matrices.
- Use derivatives, gradients, Jacobians, and integrals to analyze models and algorithms.
- Describe random variables, probability distributions, expectation, covariance, and conditional inference.
- Apply statistical estimation and validation to engineering data.
- Formulate and solve basic unconstrained and constrained optimization problems.
- Explain numerical error, conditioning, convergence, and stability.
- Implement foundational calculations in Python using reliable computational practice.
- Evaluate the limitations, safety implications, and assumptions of mathematical AI models.
1. Mathematical Representation of Mechatronic Systems1.1 Scalars, vectors, and matricesA scalar is a single numerical quantity, such as temperature T = 35 °C or motor speed ω = 120 rad/s. A vector is an ordered set of quantities. A robot state may be represented by x = [q₁, q₂, q̇₁, q̇₂]ᵀ where q₁ and q₂ are joint angles and q̇₁ and q̇₂ are angular velocities. The superscript T denotes transpose. If a vector has n components, it belongs to ℝⁿ. A matrix is a rectangular array. A linear sensor model can be written as y = Hx + v where x ∈ ℝⁿ is the state, y ∈ ℝᵐ is the measurement, H ∈ ℝᵐ×ⁿ is the measurement matrix, and v is measurement error. Matrix multiplication is defined only when the inner dimensions agree. This dimensional check is one of the simplest ways to detect modeling errors. The dot product of vectors a and b is aᵀb = ∑ᵢ aᵢbᵢ and measures alignment. The Euclidean norm is ∥x∥₂ = √(∑ᵢ xᵢ²) where the components must have compatible units. If a state combines metres and radians, direct use of its unscaled norm may be misleading; engineering scaling or nondimensionalization is then required. 1.2 Linear systems and transformationsA linear mapping satisfies f(ax + bz) = af(x) + bf(z) for scalars a,b. In mechatronics, linear models often approximate nonlinear systems near an operating point. A discrete-time state-space model is xₖ₊₁ = Axₖ + Buₖ + wₖ yₖ = Cxₖ + Duₖ + vₖ Here xₖ is the state, uₖ the input, yₖ the output, and wₖ and vₖ process and measurement disturbances. Matrices A, B, C, and D must have dimensions consistent with the state, input, and output sizes. A matrix is invertible only if it is square and has nonzero determinant. Although the inverse A⁻¹ is useful theoretically, numerical software should generally solve Ax = b directly rather than explicitly computing A⁻¹b. Factorization methods are usually faster and more stable. Eigenvalues satisfy Av = λv where v ≠ 0 is an eigenvector and λ is its eigenvalue. For a discrete linear system, asymptotic stability requires all eigenvalues of A to have magnitude less than one. This condition applies to a time-invariant, unforced linear discrete model; nonlinear and time-varying systems require additional analysis. 1.3 Least squares and the pseudoinverseSuppose a sensor model is y ≈ Xβ, where X is a known data matrix and β contains unknown parameters. Ordinary least squares minimizes the residual sum of squares: J(β) = ∥y − Xβ∥₂² If XᵀX is nonsingular, the minimizer is β̂ = (XᵀX)⁻¹Xᵀy The formula is analytically useful, but QR or singular-value decomposition is preferred computationally because forming XᵀX can worsen conditioning. When a system is underdetermined or rank-deficient, the Moore–Penrose pseudoinverse provides a minimum-norm least-squares solution, commonly computed through singular-value decomposition. 2. Calculus for Models and Learning Algorithms2.1 Derivatives and linearizationThe derivative of a scalar function f(x) is the limit df/dx = limh→0 [f(x+h) − f(x)]/h provided the limit exists. It represents local sensitivity and has units equal to the units of f divided by those of x. For example, if position s(t) is measured in metres, ds/dt is velocity in metres per second. A differentiable nonlinear function can be approximated near x₀ by f(x) ≈ f(x₀) + ∇f(x₀)ᵀ(x − x₀) For a scalar function of a vector, the gradient is ∇f = [∂f/∂x₁, ∂f/∂x₂, …, ∂f/∂xₙ]ᵀ For a vector-valued function f:ℝⁿ→ℝᵐ, the Jacobian is the m×n matrix of first partial derivatives. In robotics, a Jacobian relates joint velocities to end-effector velocity: v = J(q)q̇ The relation is local and depends on configuration q. Singular configurations occur when the Jacobian loses rank, reducing controllable motion directions and often amplifying velocity or force errors. 2.2 Chain rule and gradient descentThe chain rule permits differentiation through cascaded models. If z = g(x) and y = f(z), then dy/dx = (dy/dz)(dz/dx) In a parameterized AI model with loss L(θ), gradient descent updates parameters according to θₖ₊₁ = θₖ − η∇L(θₖ) where η > 0 is the learning rate. The update assumes a differentiable or suitably subdifferentiable objective and a gradient that is sufficiently accurate. A learning rate that is too large can cause divergence; one that is too small can make training impractically slow. For a single-variable quadratic f(x) = ½ax² with a > 0, the gradient is ax. The update becomes xₖ₊₁ = (1 − ηa)xₖ. Convergence requires |1 − ηa| < 1, or 0 < η < 2/a. This is a special result for this quadratic, not a universal learning-rate rule. 2.3 Integration and numerical differentiationIntegration accumulates a quantity. If velocity is known, displacement over an interval is s(t₂) − s(t₁) = ∫ₜ₁ᵗ₂ v(t) dt Numerical data rarely provide an exact continuous function. A common approximation is the trapezoidal rule: ∫ₐᵇ f(t)dt ≈ ∑ₖ [(tₖ₊₁ − tₖ)(fₖ + fₖ₊₁)]/2 It is accurate for linear variation between samples and generally improves as the sampling interval decreases, assuming adequate smoothness. Numerical differentiation is more sensitive to measurement noise than integration. Filtering, appropriate sampling, and model-based estimation are therefore important in velocity and acceleration calculation. 3. Probability and Uncertainty3.1 Random variables and distributionsA random variable maps uncertain outcomes to numerical values. A discrete variable has a probability mass function; a continuous variable has a probability density function p(x). A density can exceed one, but its integral over all possible values must equal one: ∫₋∞^∞ p(x)dx = 1 For an event A, probability satisfies 0 ≤ P(A) ≤ 1. The expectation and variance of a scalar random variable are E[X] = ∫ x p(x)dx Var(X) = E[(X − μ)²] where μ = E[X]. The standard deviation is σ = √Var(X), and it has the same units as X. The Gaussian distribution is frequently used for sensor noise: p(x) = [1/(σ√(2π))] exp[−(x − μ)²/(2σ²)] It is appropriate only when the measurement process is reasonably represented by a continuous, symmetric, unimodal distribution. Real sensors may exhibit bias, saturation, quantization, outliers, or non-Gaussian noise. 3.2 Covariance and correlationFor random vectors x and y, covariance is Cov(x,y) = E[(x − μₓ)(y − μᵧ)ᵀ] The covariance matrix is symmetric and positive semidefinite. Diagonal entries are variances; off-diagonal entries describe coupled uncertainty. Correlation normalizes covariance: ρₓᵧ = Cov(X,Y)/(σₓσᵧ) provided both standard deviations are nonzero. Correlation measures linear association and does not by itself establish causation. 3.3 Conditional probability and Bayes’ theoremConditional probability is P(A|B) = P(A∩B)/P(B) for P(B) > 0. Bayes’ theorem is P(A|B) = [P(B|A)P(A)]/P(B) In diagnosis, P(A) is a prior probability, P(B|A) is the likelihood, and P(A|B) is the posterior probability. The distinction is essential in fault detection: even a highly accurate alarm can have a low positive predictive value when the fault is rare. A simple Bayesian state-estimation model combines a prior distribution with a measurement likelihood. The Kalman filter is a special optimal recursive estimator for linear systems with Gaussian noise and known covariances. Its assumptions should not be silently applied to nonlinear or strongly non-Gaussian systems; extended, unscented, particle, or robust filters may then be more suitable. 4. Statistics for Engineering DataA sample mean is x̄ = (1/n)∑ᵢ₌₁ⁿ xᵢ and the unbiased sample variance is s² = [1/(n−1)]∑ᵢ₌₁ⁿ(xᵢ − x̄)² The factor n−1 applies when estimating a population variance from independent observations using the sample mean. Independence and representative sampling are important assumptions. A confidence interval quantifies uncertainty in an estimation procedure, not the probability that a fixed parameter changes. For a mean with known population standard deviation σ, a two-sided normal-based interval is x̄ ± zₐ/₂ σ/√n where zₐ/₂ is the standard-normal critical value and 1−α is the confidence level. If σ is unknown and the sample is reasonably normal, a Student’s t critical value is used instead. Regression models relationships between variables. In linear regression, residual analysis should examine nonlinearity, unequal variance, dependence, and influential observations. A high coefficient of determination R² does not prove causation and does not guarantee safe extrapolation beyond the training range. For AI in mechatronics, data should be divided into training, validation, and test sets without leakage. Time-series data require chronological or grouped splitting when random shuffling would allow future information to enter training. Performance metrics must reflect the engineering objective: false-negative rate may be more important than accuracy in safety fault detection. 5. OptimizationOptimization selects variables that minimize a cost or maximize a performance measure. A general constrained problem is minimizeₓ f(x) subject to gᵢ(x) ≤ 0, i = 1,…,m hⱼ(x) = 0, j = 1,…,p Here f is the objective, gᵢ inequality constraints, and hⱼ equality constraints. Variables may represent controller gains, trajectory points, model parameters, or actuator commands. For unconstrained differentiable optimization, a necessary first-order condition for an interior local optimum is ∇f(x*) = 0 It is not sufficient by itself: a stationary point may be a maximum or saddle point. If the Hessian ∇²f(x*) is positive definite, the point is a strict local minimum. For convex objectives over convex feasible sets, a local minimum is also global. The Lagrangian for equality constraints is ℒ(x,λ) = f(x) + λᵀh(x) where λ contains multipliers. The Karush–Kuhn–Tucker conditions extend this idea to inequalities under suitable constraint qualifications. In engineering, multipliers can provide sensitivity information: they estimate how the optimum changes when a constraint is relaxed, subject to regularity assumptions. Regularization controls model complexity. Ridge regression minimizes ∥y − Xβ∥₂² + λ∥β∥₂² where λ ≥ 0 controls penalty strength. Increasing λ generally reduces parameter magnitude and variance but may increase bias. The intercept is often excluded from the penalty when features are centered. 6. Numerical Methods and Computational Reliability6.1 Sources of errorFloating-point computation introduces round-off error because real numbers are represented with finite precision. Truncation error results from replacing an exact mathematical operation with an approximation, such as a finite difference. Measurement error originates in sensors, while model error arises when equations omit relevant physics. Conditioning describes sensitivity of a problem to small input perturbations. An ill-conditioned matrix problem can produce large output changes even when an algorithm is implemented correctly. Stability describes whether an algorithm limits the amplification of computational errors. A stable algorithm cannot fully rescue an ill-conditioned model, so both properties must be considered. 6.2 Root finding and integrationFor f(x)=0, bisection maintains an interval [a,b] with opposite signs and repeatedly halves it. If f is continuous and f(a)f(b)<0, the intermediate value theorem guarantees at least one root in the interval. Bisection is reliable but linearly convergent. Newton’s method is xₖ₊₁ = xₖ − f(xₖ)/f′(xₖ) It can converge rapidly near a simple root when the initial value is good and f′ is nonzero, but it can diverge or encounter a zero derivative. Practical software should impose iteration limits, stopping tolerances, and residual checks. For an iterative method, stopping may be based on a step criterion such as |xₖ₊₁−xₖ| ≤ εₓ and a residual criterion such as |f(xₖ)| ≤ εf. The tolerances should reflect sensor resolution, physical requirements, and numerical scale rather than arbitrary machine precision. 6.3 Python implementation practiceA dependable computational workflow is: - State variables, units, assumptions, and expected ranges.
- Test the model on a hand-computable example.
- Use array operations with NumPy and inspect dimensions explicitly.
- Use SciPy or equivalent solvers for established numerical algorithms.
- Plot residuals, distributions, trajectories, and convergence histories.
- Compare results against conservation laws, limiting cases, or an independent implementation.
- Record software versions, random seeds, data preprocessing, and solver tolerances.
For example, a least-squares implementation should prefer a solver such as numpy.linalg.lstsq(X, y, rcond=None) over explicitly calculating an inverse. Unit-aware tools or disciplined naming can prevent mixing degrees with radians, millimetres with metres, or samples with seconds. 7. Integrated Case Study: Predictive Maintenance of a Servo AxisThe following is an illustrative case, not a report of a specific industrial installation. Background and problemA two-axis servo stage positions a camera for automated inspection. Intermittent increases in motor current suggest bearing degradation, but current also changes with payload, speed, and acceleration. The engineering team wants an early-warning model that limits false alarms and provides a physically interpretable basis for maintenance. AnalysisThe measured vector at sample k is defined as zₖ = [iₖ, ωₖ, αₖ, Tₖ]ᵀ where current i is in amperes, speed ω in radians per second, acceleration α in radians per second squared, and temperature T in degrees Celsius. Data are timestamped and synchronized. Missing values and sensor saturation are flagged rather than silently imputed. A baseline regression predicts current from operating conditions: iₖ = β₀ + β₁|ωₖ| + β₂|αₖ| + β₃Tₖ + εₖ The residual rₖ = iₖ − îₖ is more informative than raw current because it removes predictable loading effects. A rolling mean and variance of residuals are monitored, while a validation set from later operating periods tests generalization. The team checks residual autocorrelation because successive samples are not independent. Approach and solutionFeatures are standardized using training-set means and standard deviations only. A regularized regression is compared with a tree-based anomaly detector. The decision threshold is selected using maintenance costs: missing a developing fault is more expensive than inspecting a healthy axis, but excessive alarms interrupt production. A simple Bayesian interpretation is also used. If the prior probability of a fault in a weekly period is 0.02, the alarm sensitivity is 0.90, and the false-alarm probability is 0.05, then P(F|A) = (0.90×0.02)/[(0.90×0.02)+(0.05×0.98)] ≈ 0.269 Thus, an alarm implies an estimated fault probability of about 26.9%, not 90%. This result supports inspection and additional evidence rather than automatic replacement. Outcome and learning pointsIn the illustrative deployment, the model is accepted as a decision-support tool rather than an autonomous safety controller. It provides ranked alerts, residual plots, confidence information, and an explanation of the operating conditions associated with each alert. Its limitations are documented: changes in payload distribution, sensor recalibration, and previously unseen failure modes can invalidate the model. The case demonstrates four principles. First, features must reflect physics and units. Second, uncertainty and base rates affect decisions. Third, chronological validation is essential for time-dependent systems. Fourth, an AI prediction should not bypass established machine-protection interlocks or human maintenance procedures. 8. Limitations, Governance, and Contemporary PracticeMathematical models are abstractions. A model may be statistically accurate under laboratory conditions yet fail after a sensor replacement, software update, environmental change, or novel operating regime. Engineers should perform sensitivity analysis, out-of-distribution checks, calibration assessment, and fault-injection testing where safe. Safety-critical AI requires traceability from requirement to data, model, software version, test evidence, and deployment decision. Access controls, audit logs, cybersecurity protections, and privacy safeguards are relevant when equipment data identify workers or production behavior. Human oversight must be meaningful: operators need understandable alerts, escalation paths, and the authority to reject an automated recommendation. Contemporary practice increasingly combines first-principles models with data-driven models. Hybrid or physics-informed approaches can improve data efficiency and constrain predictions, but they do not eliminate the need to verify assumptions. Automatic differentiation, probabilistic programming, differentiable simulation, edge AI, and uncertainty-aware deep learning are important developments. Their value depends on computational cost, validation evidence, and the consequences of error—not novelty alone. Best-Practice Checklist- Define every variable, unit, coordinate frame, and sign convention.
- Check matrix dimensions before interpreting a result.
- Scale features when magnitudes or units differ substantially.
- Prefer numerically stable factorizations to explicit matrix inversion.
- Separate training, validation, and test information to prevent leakage.
- Report uncertainty, not only a point prediction.
- Test limiting cases, residuals, conservation laws, and physical constraints.
- Monitor drift after deployment and establish retraining criteria.
- Keep safety interlocks independent of an experimental AI model.
- Document assumptions, data provenance, software versions, and decisions.
Chapter SummaryLinear algebra supplies the language of states, measurements, transformations, regression, and system models. Norms, rank, eigenvalues, Jacobians, and least-squares methods are particularly important in mechatronics. Calculus provides derivatives, gradients, Jacobians, integration, linearization, and the basis of gradient-based learning. Probability represents uncertain measurements and states through distributions, expectation, variance, covariance, and Bayes’ theorem. Statistics supports estimation, regression, validation, and responsible interpretation of data. Optimization formulates parameter fitting, trajectory generation, control, and design under objectives and constraints. Numerical methods make these formulations executable but introduce round-off, truncation, conditioning, and convergence concerns. Reliable Python practice combines dimensional checks, stable solvers, visualization, tests, and reproducibility. Finally, AI models deployed in mechatronic systems must be assessed for distribution shift, uncertainty, safety, cybersecurity, privacy, and human accountability. Mathematical competence is therefore not separate from engineering practice; it is the basis for trustworthy intelligent machines. Key TermsVector: An ordered array of numerical components. Matrix: A rectangular array representing a linear mapping or dataset. State: Variables sufficient to describe the relevant condition of a dynamic system. Jacobian: Matrix of first partial derivatives of a vector-valued function. Eigenvalue: A scalar satisfying Av = λv for a nonzero vector v. Least squares: Parameter estimation that minimizes squared residuals. Gradient: Vector of first partial derivatives of a scalar function. Hessian: Matrix of second partial derivatives. Random variable: Numerical representation of an uncertain outcome. Expectation: Probability-weighted average or mean of a random variable. Variance: Expected squared deviation from the mean. Covariance: Measure of joint variation between variables. Likelihood: Probability of observed data conditional on a model or hypothesis. Posterior: Updated probability after combining prior information with data. Regularization: Penalty used to control model complexity. Conditioning: Sensitivity of a problem’s solution to input perturbations. Round-off error: Error caused by finite numerical representation. Truncation error: Error caused by replacing an exact operation with an approximation. Data leakage: Unintended use of information unavailable at prediction time. Distribution shift: Change between training conditions and deployment conditions. Review QuestionsShort Answer Questions- Why is checking matrix dimensions important in a state-space model?
- Distinguish a gradient from a Jacobian.
- What does covariance measure, and how does it differ from variance?
- Why should explicit matrix inversion generally be avoided in numerical code?
- What is data leakage, and why does it produce misleading AI evaluation?
Long Answer Questions- Explain how linearization and Jacobians are used in robotic motion and control, including their limitations near singular configurations.
- Describe Bayes’ theorem and explain how base rates affect interpretation of a predictive-maintenance alarm.
- Compare gradient descent, bisection, and Newton’s method with respect to assumptions, convergence, and failure modes.
- Explain how regularization, validation, and feature scaling affect a regression model for a mechatronic sensor.
- Discuss the numerical and governance requirements for deploying an AI model in a safety-relevant machine.
Analytical / Application Questions- A sensor model is y = Hx + v with two measurements and three state variables. Explain whether the state can be uniquely recovered from one measurement vector and identify the matrix property that must be examined.
- A fault detector has a fault prior of 1%, sensitivity of 95%, and false-alarm probability of 4%. Derive the posterior probability of a fault after an alarm and explain its engineering meaning.
- Design a validation plan for a servo-axis anomaly detector when data are collected continuously over six months. Specify the data split, metrics, leakage risks, drift checks, and action to be taken when uncertainty is high.
Multiple Choice Questions with AnswersQuestion 1Which equation represents a discrete-time linear state-space model? A. xₖ₊₁ = Axₖ + Buₖ + wₖ B. xₖ₊₁ = A + Bxₖuₖ C. y = x² + c D. xₖ₊₁ = xₖ/A − B Correct Answer: A. xₖ₊₁ = Axₖ + Buₖ + wₖ Question 2For a discrete-time linear system, which condition indicates asymptotic stability of the time-invariant unforced model? A. All eigenvalues have positive real parts. B. All eigenvalues have magnitude less than one. C. The determinant is exactly one. D. The matrix contains only positive entries. Correct Answer: B. All eigenvalues have magnitude less than one. Question 3What is the main purpose of a Jacobian in robotic kinematics? A. To convert probabilities into frequencies. B. To relate local joint velocities to end-effector velocities. C. To calculate a sample variance only. D. To guarantee global optimization. Correct Answer: B. To relate local joint velocities to end-effector velocities. Question 4If X is a scalar random variable with mean μ, which expression defines its variance? A. E[X B. E[(X−μ)² C. E[X−μ²]] D. 1/E[X² Correct Answer: B. E[(X−μ)² Question 5A fault has prior probability 0.02, alarm sensitivity 0.90, and false-alarm probability 0.05. Approximately what is the probability of a fault given an alarm? A. 2.0% B. 5.0% C. 26.9% D. 90.0% Correct Answer: C. 26.9% Question 6Which method is generally preferred to explicitly computing (XᵀX)⁻¹Xᵀy in numerical least squares? A. QR or singular-value decomposition B. Randomly deleting rows C. Rounding all values to integers D. Ignoring matrix rank Correct Answer: A. QR or singular-value decomposition Question 7What is a necessary first-order condition for an interior differentiable local optimum? A. ∇f(x*) = 0 B. f(x*) = 1 C. det(x*) = 0 D. The Hessian must be negative for every problem. Correct Answer: A. ∇f(x*) = 0 Question 8Which statement about Newton’s root-finding method is correct? A. It always converges from any initial value. B. It requires a derivative and can fail with a poor initial value. C. It can only be used for linear functions. D. It never needs a stopping criterion. Correct Answer: B. It requires a derivative and can fail with a poor initial value. Question 9Why is chronological splitting often appropriate for mechatronic time-series data? A. It guarantees zero measurement noise. B. It prevents future information from entering model training. C. It makes all observations independent. D. It removes the need for a test set. Correct Answer: B. It prevents future information from entering model training. Question 10Which practice best supports trustworthy deployment of an AI model in a safety-relevant machine? A. Allowing the model to bypass hardware interlocks B. Reporting only the most favorable test result C. Documenting assumptions, uncertainty, versions, and validation evidence D. Using the largest model regardless of computational cost Correct Answer: C. Documenting assumptions, uncertainty, versions, and validation evidence
|