Introduction to Linear Algebra using MATLAB
Versione 1.0.0 (147 KB) da
Pratik
Linear Algebra is a fundamental branch of mathematics that deals with vectors, matrices, and linear transformations, forming the backbone of
%% Introduction to Linear Algebra using MATLAB
% Example: Solve the system of linear equations
% 2x + 3y = 8
% x - y = 1
clc; % Clear the Command Window
clear; % Clear all variables
close all; % Close all figures
% Step 1: Define coefficient matrix A
A = [2 3;
1 -1];
% Step 2: Define constant matrix b
b = [8;
1];
% Step 3: Solve for x using matrix division (A\b)
x = A\b;
% Step 4: Display the result
disp('Solution of the system A*x = b is:');
Solution of the system A*x = b is:
fprintf('x = %.2f\n', x(1));
x = 2.20
fprintf('y = %.2f\n\n', x(2));
y = 1.20
% Step 5: Verify the solution
check = A*x;
disp('Verification (A*x):');
Verification (A*x):
disp(check);
8.0000
1.0000
disp('It should be equal to vector b:');
It should be equal to vector b:
disp(b);
1
8
1
% Step 6: Optional - visualize the two equations
x_vals = -5:0.1:5; % Range for plotting
% Equation 1: 2x + 3y = 8 => y = (8 - 2x)/3
y1 = (8 - 2*x_vals)/3;
% Equation 2: x - y = 1 => y = x - 1
y2 = x_vals - 1;
figure;
plot(x_vals, y1, 'r', 'LineWidth', 2); hold on;
plot(x_vals, y2, 'b', 'LineWidth', 2);
grid on;
xlabel('x'); ylabel('y');
title('Graphical Solution of Linear Equations');
legend('2x + 3y = 8', 'x - y = 1', 'Location', 'best');
text(x(1), x(2), sprintf(' Solution (%.2f, %.2f)', x(1), x(2)), 'FontSize',
10, 'Color', 'k');
Cita come
Pratik (2025). Introduction to Linear Algebra using MATLAB (https://it.mathworks.com/matlabcentral/fileexchange/182526-introduction-to-linear-algebra-using-matlab), MATLAB Central File Exchange. Recuperato .
Compatibilità della release di MATLAB
Creato con
R2025b
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS LinuxTag
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Scopri Live Editor
Crea script con codice, output e testo formattato in un unico documento eseguibile.
| Versione | Pubblicato | Note della release | |
|---|---|---|---|
| 1.0.0 |
