matlab-symbolic-math — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited matlab-symbolic-math (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
This skill provides guidelines, correct syntax, and common patterns for generating MATLAB® code that uses Symbolic Math Toolbox.
WRONG (deprecated — warns today, errors in a future release; the single `=` in `solve` errors now):
solve('x^2 + 2*x - 3 = 0')
dsolve('Dy = -a*y')CORRECT:
syms x
solve(x^2 + 2*x - 3 == 0, x)
syms y(t) a
dsolve(diff(y,t) == -a*y)syms for Interactive Work, sym for Functions and Constantssyms dynamically creates workspace variables.pi, NOT the mathematical constant π. This is a common source of confusion.WRONG:
% Inside a function:
function result = myFunc()
syms x % Error or unreliable in compiled/nested functions
result = x^2;
end
% Creating symbolic constant pi:
p = sym('pi'); % Creates variable named "pi", NOT the constantCORRECT:
% Inside a function:
function result = myFunc()
x = sym('x'); % Use sym inside functions
result = x^2;
end
% Creating symbolic constant pi:
p = sym(pi); % Converts numeric pi to exact symbolic πAssumptions persist in the symbolic engine even after clear. This is a frequent source of subtle bugs.
% Setting assumptions
syms x real % x is real (clears prior assumptions)
syms n positive integer % n is a positive integer
assume(x > 0) % x is positive (REPLACES all prior assumptions on x)
assumeAlso(x < 10) % ADDS assumption: 0 < x < 10
% Checking assumptions
assumptions(x) % Shows assumptions on x
assumptions % Shows ALL assumptions in workspace
% Clearing assumptions — THREE ways (know the differences):
syms x % Recreate with syms: clears assumptions
assume(x, 'clear') % Explicitly clear assumptions on x
reset(symengine) % Nuclear option: clears EVERYTHING
% DANGER: clear x does NOT clear assumptions!
clear x % Removes variable from workspace
x = sym('x'); % x INHERITS old assumptions from engine!Best Practice: Use syms to create variables at the start of a script. This clears stale assumptions. Use assume(x, 'clear') when you need to reset a specific variable mid-script.
subs Does Not Modify In-PlaceThe subs function returns a new expression. It does NOT modify the original.
WRONG:
syms x
f = x^2 + 3*x;
subs(f, x, 2); % Result is discarded!
disp(f) % Still x^2 + 3*xCORRECT:
syms x
f = x^2 + 3*x;
f_val = subs(f, x, 2); % Assign the result
% or: f = subs(f, x, 2); % Overwrite fsym() Inside Symbolic ExpressionsAI tools frequently over-wrap every numeric literal in sym(). When any operand in an arithmetic expression is symbolic, MATLAB automatically promotes all numeric literals in that expression to symbolic. Wrapping literals in sym() adds clutter and can cause errors. When you DO need `sym()`: Only when creating a standalone symbolic number with NO symbolic variables present in the expression.
% No symbolic variable involved — sym() IS needed:
half = sym(1/2); % Exact 1/2, not 0.5 double
half = sym(1)/2; % Exact 1/2, declaring sym(1) promotes all numeric literals to symbolic
piExact = sym(pi); % Exact π, not 3.14159...
% Symbolic variable already present — sym() is NOT needed:
syms x
f = x/2 + 1/3; % Automatically exact: x/2 + 1/3
g = exp(-x^2/2) / sqrt(2*pi); % All literals promoted by xWhen substituting numeric values or converting symbolic expressions to numeric form, keep the base variable name and append a suffix indicating the conversion type:
subs() or double() (numeric value)vpa() (variable-precision arithmetic)syms m g L
% Substituting numeric values
mVal = double(subs(m, 5)); % or: mVal = 5;
gVal = 9.81;
LVal = 0.5;
% Evaluating a symbolic expression numerically
omega = sqrt(g/L);
omegaVal = double(subs(omega, [g L], [gVal LVal]));
% Variable-precision arithmetic
piVpa = vpa(sym(pi), 50);
omegaVpa = vpa(subs(omega, [g L], [gVal LVal]), 32);Rationale: This convention keeps symbolic and numeric variables visually distinct in the workspace, avoids accidentally overwriting a symbolic expression with a numeric value, and makes it clear at a glance which variables are exact symbolic vs. evaluated numeric.
% Multiple variables at once
syms a b c
% Variables with assumptions
syms a b c real
syms n positive integer
syms x
assume(x > 2)
% Symbolic matrices with auto-generated elements
syms A [3 3] % Creates A = [A1_1 A1_2 A1_3; ...]
% Symbolic vector
syms a [1 3] % Creates row vector a = [a1 a2 a3]
% Symbolic numbers (exact)
a = sym(1/3); % Exact 1/3
piSym = sym(pi); % Exact πsyms x y
% Single equation
sol = solve(x^2 - 5*x + 6 == 0, x); % Returns [2; 3]
% System of equations
[solx, soly] = solve(x + y == 10, x - y == 2, x, y);
% Return all solutions along with the parameters in the solution and the conditions on the solution
[sol, params, conds] = solve(sin(x) == 0, x, 'ReturnConditions', true);
% Numerical solutions when analytic not possible
solN = vpasolve(x^5 - 3*x^4 + x - 1 == 0, x);syms x t n
% Differentiation
diff(sin(x), x) % cos(x)
diff(x^3, x, 2) % 6*x (second derivative)
% Integration
int(x^2, x) % x^3/3 (indefinite)
int(x^2, x, 0, 1) % 1/3 (definite, from 0 to 1)
% Limits
limit(sin(x)/x, x, 0) % 1
limit(1/x, x, 0, 'right') % Inf
limit(1/x, x, 0, 'left') % -Inf
% Summation
symsum(1/n^2, n, 1, Inf) % pi^2/6
% Taylor series
taylor(exp(x), x, 0, 'Order', 6) % x^5/120 + x^4/24 + x^3/6 + x^2/2 + x + 1 syms a b c d
A = [a b; c d];
% Determinant
det(A) % a*d - b*c
% Inverse
inv(A) % Symbolic inverse
% Eigenvalues and eigenvectors
[V, D] = eig(A)
% Characteristic polynomial
charpoly = det(A - sym('lambda')*eye(2))
% Jacobian
syms x y
f = [x^2*y; 5*x + sin(y)];
J = jacobian(f, [x, y]) % [2*x*y, x^2; 5, cos(y)]
% Jacobian of a coordinate change
syms r(t) phi(t) theta(t); % polar coordinates that are a function of time
R = [r*sin(phi)*cos(theta), r*sin(phi)*sin(theta), r*cos(phi)] % coordinate transform from spherical to Cartesian
jacobian(R,[r,phi,theta])For detailed workflows, see the reference files below. Read the relevant file when the user's task matches:
simplify/expand/factor/collect/partfrac/rewrite, sym2poly vs coeffs, variable-precision arithmetic (VPA)tf/ss derivation from first principles, Laplace/Fourier/Z-transform, Bode plots from symbolic modelsdsolve syntax, odeToVectorField + matlabFunction + ode45 pipeline, parameterized ODE solvingfplot/fsurf/fmesh/fcontour/fimplicit/fanimator family, disp() vs pretty(), why NOT to use linspace+subs+plot'Vars'/'Optimize'/'File' options, piecewise handling, critical error-prevention rules| Mistake | Fix |
|---|---|
solve('x^2=1') | syms x; solve(x^2 == 1, x) |
dsolve('Dy = y') | syms y(t); dsolve(diff(y,t) == y) |
subs(f,x,2) without assigning | f = subs(f,x,2) |
clear x to clear assumptions | syms x or assume(x,'clear') |
Using syms inside a function | Use x = sym('x') inside functions |
See also: application-specific mistakes in each reference file.
syms (not string-based sym('...')) for variable creation in scripts== for equations, not =diff(y, t, n) for derivatives, not D notationdiff, int, laplacesubs(...) output to a variablesym() when a symbolic variable is already in the expressionassume/assumeAlso, clearing with syms or assume(x,'clear')Issue: solve returns empty or unexpected results
assumptions to check.solve(eqn, x, 'ReturnConditions', true) to see conditions on solutions.vpasolve for numeric solutions when no closed form exists.Issue: Stale assumptions causing wrong results
syms <varname> at the top of your script to clear assumptions.reset(symengine) clears everything.See also: application-specific troubleshooting in each reference file.
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.