Keywords: MATLAB | vector drawing | quiver | visualization | vector addition
Abstract: This article provides a detailed guide on drawing 2D and 3D vectors in MATLAB using the quiver and quiver3 functions. It explains how to visualize vector addition through head-to-tail and parallelogram methods, with code examples and supplementary tools like the arrow.m function.
Introduction
In MATLAB, visualizing vectors is essential for physical simulations and data analysis. This guide focuses on drawing vectors with arrowheads to represent magnitude and direction.
Using the quiver Function
The simplest way to plot vectors in MATLAB is by using the quiver function for 2D or quiver3 for 3D vectors. For example, to plot vectors a, b, and their sum c:
a = [2 3 5];
b = [1 1 0];
c = a + b;
starts = zeros(3,3);
ends = [a; b; c];
quiver3(starts(:,1), starts(:,2), starts(:,3), ends(:,1), ends(:,2), ends(:,3))
axis equalThis code creates arrows from the origin to each vector's endpoint.
Visualizing Vector Addition
To illustrate head-to-tail method, use multiple arrows. For parallelogram method, additional lines can be drawn using the line function.
Supplementary Tools
Alternatively, the arrow.m function from MathWorks File Exchange offers more flexibility. It allows custom arrow plotting for complex visualizations.
Conclusion
MATLAB provides robust functions for vector visualization, with quiver being the standard and external tools enhancing capabilities.