Install any skill in seconds. Free to start, no credit card required.
Get Started Free →MATLAB/GNU Octave numerical computing: matrices, linear algebra, ODEs, signal processing, optimization, statistics, scientific visualization. MATLAB-syntax examples run on both. For Python use numpy/scipy; for statistical modeling use statsmodels.
.claude/skills/jaechang-hits-matlab-scientific-computing/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-04 | ✗→✓ | ▲ Improved | 216% | 0% |
| case-12 | ✗→✓ | ▲ Improved | 148% | 0% |
| case-16 | ✗→✓ | ▲ Improved | 510% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 270% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 223% | 0% |
MATLAB is a numerical computing environment optimized for matrix operations and scientific computing. GNU Octave is a free, open-source alternative with high compatibility. All code examples use MATLAB syntax that runs on both platforms.
bash# GNU Octave (free, open-source) # macOS brew install octave # Ubuntu/Debian sudo apt install octave # Running scripts octave script.m # Octave matlab -nodisplay -nosplash -r "run('script.m'); exit;" # MATLAB
Note: MATLAB requires a commercial license from MathWorks. GNU Octave is free and runs most MATLAB scripts without modification. Key Octave differences: supports # comments, ++/+= operators; some MATLAB toolbox functions unavailable.
matlab% Load data, fit, and plot x = linspace(0, 2*pi, 100); y = sin(x) + 0.1 * randn(size(x)); p = polyfit(x, y, 5); y_fit = polyval(p, x); figure; plot(x, y, 'bo', x, y_fit, 'r-', 'LineWidth', 2); xlabel('x'); ylabel('y'); legend('Data', 'Polynomial fit'); title('Curve Fitting Example'); saveas(gcf, 'fit_result.png');
MATLAB operates fundamentally on matrices and arrays.
matlab% Create matrices A = [1 2 3; 4 5 6; 7 8 9]; % 3x3 matrix v = linspace(0, 1, 100); % 100 evenly spaced points I = eye(3); % Identity matrix R = rand(3, 3); % Uniform random N = randn(3, 3); % Normal random % Operations B = A'; % Transpose C = A * B; % Matrix multiplication D = A .* B; % Element-wise multiplication x = A \ [1; 2; 3]; % Solve Ax = b (preferred over inv(A)*b) fprintf('Solution: [%.2f, %.2f, %.2f]\n', x);
matlab% Indexing and manipulation A = magic(5); sub = A(1:3, 2:4); % Submatrix (rows 1-3, cols 2-4) row = A(2, :); % Entire row 2 col = A(:, 3); % Entire column 3 A(A < 5) = 0; % Logical indexing % Concatenation C = [A; ones(1, 5)]; % Vertical (add row) D = [A, zeros(5, 1)]; % Horizontal (add column) fprintf('Size: %d x %d\n', size(C));
matlabA = [4 1 2; 1 3 1; 2 1 5]; % Eigendecomposition [V, D] = eig(A); % V: eigenvectors, D: diagonal eigenvalues fprintf('Eigenvalues: %.2f, %.2f, %.2f\n', diag(D)); % Singular value decomposition [U, S, V] = svd(A); fprintf('Singular values: %.2f, %.2f, %.2f\n', diag(S)); % Matrix decompositions [L, U, P] = lu(A); % LU with pivoting [Q, R] = qr(A); % QR decomposition R_chol = chol(A); % Cholesky (symmetric positive definite) % Condition number and rank fprintf('Condition number: %.2f\n', cond(A)); fprintf('Rank: %d\n', rank(A));
matlab% 2D line plots x = 0:0.1:2*pi; figure; plot(x, sin(x), 'b-', 'LineWidth', 2); hold on; plot(x, cos(x), 'r--', 'LineWidth', 2); xlabel('x'); ylabel('y'); title('Trigonometric Functions'); legend('sin(x)', 'cos(x)'); grid on; saveas(gcf, 'trig.png');
matlab% 3D surface plot [X, Y] = meshgrid(-2:0.1:2, -2:0.1:2); Z = X.^2 + Y.^2; figure; surf(X, Y, Z); colorbar; xlabel('X'); ylabel('Y'); zlabel('Z'); title('Paraboloid'); print('-dpdf', 'surface.pdf');
matlab% Multi-panel figure figure; subplot(2, 2, 1); plot(x, sin(x)); title('sin'); subplot(2, 2, 2); plot(x, cos(x)); title('cos'); subplot(2, 2, 3); bar([1 3 2 5 4]); title('Bar'); subplot(2, 2, 4); histogram(randn(1000, 1), 30); title('Histogram'); saveas(gcf, 'panels.png');
matlab% CSV / tabular data T = readtable('data.csv'); M = readmatrix('data.csv'); fprintf('Table: %d rows x %d cols\n', height(T), width(T)); % Write data writetable(T, 'output.csv'); writematrix(M, 'output.csv'); % MAT files (MATLAB native binary) A = rand(100, 100); save('data.mat', 'A'); % Save variable S = load('data.mat', 'A'); % Load specific variable % Images img = imread('image.png'); fprintf('Image size: %d x %d x %d\n', size(img)); imwrite(img, 'output.jpg');
matlabdata = randn(1000, 1) * 5 + 50; % Descriptive statistics fprintf('Mean: %.2f, Std: %.2f, Median: %.2f\n', mean(data), std(data), median(data)); fprintf('Min: %.2f, Max: %.2f\n', min(data), max(data)); % Correlation and covariance X = randn(100, 3); R = corrcoef(X); fprintf('Correlation matrix:\n'); disp(R); % Linear regression (polyfit) x = (1:50)'; y = 2.5 * x + 10 + randn(50, 1) * 5; p = polyfit(x, y, 1); fprintf('Slope: %.2f, Intercept: %.2f\n', p(1), p(2)); % Moving statistics y_smooth = movmean(y, 5);
matlab% First-order ODE: dy/dt = -2y, y(0) = 1 f = @(t, y) -2 * y; [t, y] = ode45(f, [0 5], 1); figure; plot(t, y, 'b-', 'LineWidth', 2); xlabel('Time'); ylabel('y(t)'); title('Exponential Decay'); fprintf('Final value: %.4f (expected: %.4f)\n', y(end), exp(-10));
matlab% Second-order ODE: y'' + 0.5y' + 4y = 0 (damped oscillator) % Convert to system: y1' = y2, y2' = -0.5*y2 - 4*y1 f = @(t, y) [y(2); -0.5*y(2) - 4*y(1)]; [t, y] = ode45(f, [0 20], [1; 0]); figure; plot(t, y(:,1), 'b-', 'LineWidth', 2); xlabel('Time'); ylabel('Displacement'); title('Damped Oscillator');
matlab% Generate signal with two frequencies fs = 1000; % Sampling frequency t = 0:1/fs:1-1/fs; signal = sin(2*pi*50*t) + 0.5*sin(2*pi*120*t) + randn(size(t))*0.2; % FFT Y = fft(signal); f = (0:length(Y)-1) * fs / length(Y); figure; plot(f(1:length(f)/2), abs(Y(1:length(Y)/2))); xlabel('Frequency (Hz)'); ylabel('|FFT|'); title('Frequency Spectrum');
matlab% FIR low-pass filter (keep < 80 Hz) b = fir1(50, 80/(fs/2)); % 50th order, cutoff 80 Hz filtered = filter(b, 1, signal); figure; plot(t, signal, 'b', t, filtered, 'r', 'LineWidth', 1.5); legend('Original', 'Filtered'); title('Low-pass Filtering');
matlab% Anonymous functions f = @(x) x.^2 + 2*x + 1; fprintf('f(5) = %d\n', f(5)); % 36 % Function files (save as myfunc.m) % function [rmse, r2] = myfunc(y_true, y_pred) % residuals = y_true - y_pred; % rmse = sqrt(mean(residuals.^2)); % ss_res = sum(residuals.^2); % ss_tot = sum((y_true - mean(y_true)).^2); % r2 = 1 - ss_res / ss_tot; % end % Struct for organized data experiment.name = 'Trial 1'; experiment.data = rand(10, 3); experiment.params = struct('temp', 37, 'pH', 7.4); fprintf('Experiment: %s, %d samples\n', experiment.name, size(experiment.data, 1));
MATLAB is optimized for vectorized operations. Avoid explicit loops when possible:
matlab% Slow (loop) n = 1e6; y = zeros(1, n); tic; for i = 1:n y(i) = sin(i/1000); end t_loop = toc; % Fast (vectorized) tic; y = sin((1:n)/1000); t_vec = toc; fprintf('Loop: %.3fs, Vectorized: %.3fs, Speedup: %.1fx\n', t_loop, t_vec, t_loop/t_vec);
| Operator | Matrix | Element-wise | |----------|--------|-------------| | Multiply | A * B | A .* B | | Divide | A / B (right div) | A ./ B | | Power | A ^ n (matrix power) | A .^ n |
| Solver | Order | When to Use | |--------|-------|-------------| | ode45 | 4-5 | Default. Most non-stiff problems | | ode23 | 2-3 | Rough solutions, faster per step | | ode113 | variable | High-accuracy, expensive evaluations | | ode15s | variable | Stiff problems (chemical kinetics, circuits) | | ode23s | 2 | Stiff, moderate accuracy |
matlab% 1. Load data data = readtable('experiment.csv'); % 2. Clean data = rmmissing(data); fprintf('After cleaning: %d rows\n', height(data)); % 3. Group analysis groups = unique(data.Category); results = table(); for i = 1:length(groups) mask = strcmp(data.Category, groups{i}); subset = data(mask, :); row = table(groups(i), mean(subset.Value), std(subset.Value), ... 'VariableNames', {'Category', 'Mean', 'Std'}); results = [results; row]; end disp(results); % 4. Visualize and save figure; bar(categorical(results.Category), results.Mean); hold on; errorbar(1:height(results), results.Mean, results.Std, '.k'); ylabel('Mean Value'); title('Results by Category'); saveas(gcf, 'results.png'); writetable(results, 'summary.csv');
matlab% 1D heat equation: du/dt = alpha * d2u/dx2 L = 1; N = 100; T_end = 0.5; alpha = 0.01; dx = L / (N - 1); dt = 0.4 * dx^2 / alpha; % CFL condition x = linspace(0, L, N); nsteps = floor(T_end / dt); % Initial condition: Gaussian pulse u = exp(-50 * (x - 0.5).^2); % Time stepping (explicit finite difference) figure; for step = 1:nsteps u_new = u; for i = 2:N-1 u_new(i) = u(i) + alpha * dt / dx^2 * (u(i+1) - 2*u(i) + u(i-1)); end u = u_new; if mod(step, floor(nsteps/5)) == 0 plot(x, u, 'LineWidth', 1.5); hold on; end end xlabel('Position'); ylabel('Temperature'); title('Heat Equation Evolution'); legend(arrayfun(@(n) sprintf('t=%.2f', n*dt*floor(nsteps/5)), 1:5, 'UniformOutput', false)); saveas(gcf, 'heat_equation.png');
dir('data/*.csv')readtable()vertcat()writetable()| Parameter | Function | Default | Range | Effect | |-----------|----------|---------|-------|--------| | Order | polyfit | — | 1–20 | Polynomial degree for fitting | | tspan | ode45 | — | t0, tf] | Integration time interval | | 'LineWidth' | plot | 0.5 | 0.1–5 | Line thickness in plots | | bins | histogram | auto | 1–1000 | Number of histogram bins | | Filter order | fir1 | — | 10–200 | FIR filter order (higher = sharper) | | 'RelTol' | ode45 | 1e-3 | 1e-12–1e-1 | Relative error tolerance | | 'AbsTol' | ode45 | 1e-6 | 1e-15–1e-1 | Absolute error tolerance |
bsxfun, logical indexing, and array operations.matlab % Bad: y = []; for i=1:n, y = [y, f(i)]; end % Good: y = zeros(1, n); for i = 1:n, y(i) = f(i); end
\ instead of inv() for linear systems: A\b is numerically more stable and faster than inv(A)*b.== for floating-point comparison: Use abs(a - b) < tol instead of a == b due to floating-point precision.print('-dpdf', 'fig.pdf') or print('-dsvg', 'fig.svg') instead of PNG for scalable figures.fprintf over disp for formatted output: fprintf gives control over number formatting; disp only shows raw values.matlabx = (1:20)'; y = 3 * exp(-0.2 * x) + 0.5 * randn(size(x)); % Nonlinear fit using lsqcurvefit (Optimization Toolbox) % Or use polyfit for polynomial: p = polyfit(x, y, 3); y_fit = polyval(p, x); residuals = y - y_fit; rmse = sqrt(mean(residuals.^2)); fprintf('RMSE: %.4f\n', rmse); figure; plot(x, y, 'ko', x, y_fit, 'r-', 'LineWidth', 2); xlabel('x'); ylabel('y'); title(sprintf('Polynomial Fit (RMSE = %.3f)', rmse)); saveas(gcf, 'curvefit.png');
matlabimg = imread('sample.png'); gray = rgb2gray(img); % Edge detection edges = edge(gray, 'Canny'); % Display figure; subplot(1, 3, 1); imshow(img); title('Original'); subplot(1, 3, 2); imshow(gray); title('Grayscale'); subplot(1, 3, 3); imshow(edges); title('Edges'); saveas(gcf, 'image_processing.png');
matlab% Call Python from MATLAB (requires Python on PATH) result = py.numpy.array([1, 2, 3, 4, 5]); py_mean = py.numpy.mean(result); fprintf('Python numpy mean: %.1f\n', double(py_mean)); % Call MATLAB from Python (requires matlab.engine) % import matlab.engine % eng = matlab.engine.start_matlab() % result = eng.sqrt(42.0)
| Problem | Cause | Solution | |---------|-------|----------| | Undefined function or variable | Function not on path or misspelled | Check which funcname; add path with addpath() | | Dimension mismatch in * | Matrix sizes incompatible | Use .* for element-wise; check size() of both operands | | ODE solver very slow | Stiff problem with non-stiff solver | Switch to ode15s or ode23s for stiff systems | | Singular matrix warning | Matrix is rank-deficient | Check cond(A); use pinv() (pseudo-inverse) or regularize | | Octave pkg error | Package not installed | Run pkg install -forge package_name; pkg load package_name | | Figure not saving | No figure handle active | Create figure explicitly with figure; before plotting | | Out of memory | Large array allocation | Use sparse matrices (sparse()), process in chunks, or increase swap |
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | pass→pass | 11,383 | 5,582 | -51% | 1 | 1 | 0% | 1,594 | 5,904 | +270% | 0 | 0 | — |
case-02 | pass→pass | 11,150 | 6,086 | -45% | 1 | 1 | 0% | 1,898 | 6,133 | +223% | 0 | 0 | — |
case-03 | pass→pass | 10,499 | 5,703 | -46% | 1 | 1 | 0% | 1,834 | 5,995 | +227% | 0 | 0 | — |
case-04 | fail→pass | 10,624 | 5,609 | -47% | 1 | 1 | 0% | 1,850 | 5,844 | +216% | 0 | 0 | — |
case-05 | pass→pass | 8,299 | 4,650 | -44% | 1 | 1 | 0% | 1,561 | 5,888 | +277% | 0 | 0 | — |
case-06 | pass→pass | 4,400 | 3,194 | -27% | 1 | 1 | 0% | 742 | 5,534 | +646% | 0 | 0 | — |
case-07 | pass→pass | 7,294 | 3,457 | -53% | 1 | 1 | 0% | 1,485 | 5,665 | +281% | 0 | 0 | — |
case-08 | pass→pass | 5,571 | 2,448 | -56% | 1 | 1 | 0% | 1,035 | 5,515 | +433% | 0 | 0 | — |
case-09 | pass→pass | 5,185 | 3,353 | -35% | 1 | 1 | 0% | 921 | 5,623 | +511% | 0 | 0 | — |
case-10 | pass→pass | 6,393 | 6,265 | -2% | 1 | 1 | 0% | 1,205 | 6,371 | +429% | 0 | 0 | — |
case-11 | pass→pass | 9,153 | 3,382 | -63% | 1 | 1 | 0% | 1,769 | 5,645 | +219% | 0 | 0 | — |
case-12 | fail→pass | 14,854 | 9,922 | -33% | 1 | 1 | 0% | 2,765 | 6,861 | +148% | 0 | 0 | — |
case-13 | pass→pass | 6,051 | 4,014 | -34% | 1 | 1 | 0% | 976 | 5,741 | +488% | 0 | 0 | — |
case-14 | pass→pass | 6,604 | 2,482 | -62% | 1 | 1 | 0% | 1,209 | 5,426 | +349% | 0 | 0 | — |
case-15 | pass→pass | 4,678 | 2,216 | -53% | 1 | 1 | 0% | 828 | 5,391 | +551% | 0 | 0 | — |
case-16 | fail→pass | 5,501 | 3,048 | -45% | 1 | 1 | 0% | 918 | 5,598 | +510% | 0 | 0 | — |
case-17 | pass→pass | 6,940 | 2,856 | -59% | 1 | 1 | 0% | 1,329 | 5,523 | +316% | 0 | 0 | — |
case-18 | pass→pass | 4,363 | 2,533 | -42% | 1 | 1 | 0% | 687 | 5,452 | +694% | 0 | 0 | — |
case-19 | pass→pass | 3,721 | 2,850 | -23% | 1 | 1 | 0% | 605 | 5,473 | +805% | 0 | 0 | — |
case-20 | pass→pass | 4,048 | 4,117 | +2% | 1 | 1 | 0% | 684 | 5,760 | +742% | 0 | 0 | — |
case-21 | pass→pass | 6,868 | 4,535 | -34% | 1 | 1 | 0% | 884 | 5,750 | +550% | 0 | 0 | — |
case-22 | pass→pass | 12,465 | 9,152 | -27% | 1 | 1 | 0% | 1,870 | 6,700 | +258% | 0 | 0 | — |
case-23 | pass→pass | 12,974 | 7,674 | -41% | 1 | 1 | 0% | 2,325 | 6,371 | +174% | 0 | 0 | — |
case-24 | pass→pass | 7,489 | 4,653 | -38% | 1 | 1 | 0% | 1,380 | 5,915 | +329% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 24 cases were attempted. The headline lift of +13 percentage points is the difference between those two pass rates over the 24 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.