How can I draw the graph for this system of linear equation in MATLAB?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
A=[1 2 4; 5 7 9; 10 11 12]
B=[2;4;7]
X=inv(A)*B
Now what can I do to make the graph for this system of linear equation? I mean i need a graph from which we can easily understand the intersecting points.
0 commentaires
Réponses (1)
Aashray
le 25 Juin 2025
Modifié(e) : Aashray
le 25 Juin 2025
I understand that you are trying to visualize the solution of a system of linear equations using matrices A and B. One way you can approach this problem is plotting three planes represented by each equation and showing their intersection point, which is the solution to Ax = B.
You can refer to the following script for your query:
A = [1 2 4;
5 7 9;
10 11 12];
B = [2; 4; 7];
[x, y] = meshgrid(-10:1:10, -10:1:10);
% Extract coefficients from A and B
a1 = A(1,1); b1 = A(1,2); c1 = A(1,3); d1 = B(1);
a2 = A(2,1); b2 = A(2,2); c2 = A(2,3); d2 = B(2);
a3 = A(3,1); b3 = A(3,2); c3 = A(3,3); d3 = B(3);
% Solve for z in terms of x and y: ax + by + cz = d => z = (d - ax - by)/c
z1 = (d1 - a1*x - b1*y)/c1;
z2 = (d2 - a2*x - b2*y)/c2;
z3 = (d3 - a3*x - b3*y)/c3;
% Solve the system
X = A\B;
% Plot
figure;
surf(x, y, z1, 'FaceAlpha', 0.5, 'EdgeColor', 'none'); hold on;
surf(x, y, z2, 'FaceAlpha', 0.5, 'EdgeColor', 'none');
surf(x, y, z3, 'FaceAlpha', 0.5, 'EdgeColor', 'none');
% Plot intersection point
plot3(X(1), X(2), X(3), 'ko', 'MarkerSize', 10, 'MarkerFaceColor', 'r');
xlabel('x'); ylabel('y'); zlabel('z');
title('Intersection of Three Planes from System Ax = B');
legend('Plane 1', 'Plane 2', 'Plane 3', 'Solution Point');
grid on; axis equal; view(3);
The point where all three planes intersect, that is the solution!
PS: The “FaceAlpha” parameter used in “surf” function modifies the transparency of the plot. You can read more about it from MathWorks documentation : https://www.mathworks.com/help/matlab/ref/surf.html
0 commentaires
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!