2009-12-26 20 views
20

मैं MATLAB में वैक्टर प्लॉट करने का सबसे आसान तरीका जानना चाहता हूं। उदाहरण के लिए:MATLAB में वैक्टर (भौतिक 2 डी/3 डी वैक्टर) कैसे आकर्षित करें?

a = [2 3 5]; 
b = [1 1 0]; 
c = a + b; 

मैं शीर्ष-से-पूंछ/समानांतर चतुर्भुज विधि के रूप में इस सदिश अलावा कल्पना करने के लिए चाहते हैं। मैं इन वैक्टरों को तीर-सिर के साथ कैसे प्लॉट करूं?

उत्तर

23
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 equal 
+0

तरकश quiver और quiver3 प्रलेखन पर और वैक्टर जो कर वैक्टर छोटे परिमाण के साथ की तरह लग रही के बीच खाली रिक्त स्थान छोड़ quiver3 आधार पर। – Aamir

+4

स्वत: स्केलिंग को रोकने के लिए, "स्केल" पैरामीटर जोड़ने, शून्य पर सेट करने का प्रयास करें, यानी 'quiver3 (प्रारंभ (:, 1), प्रारंभ (:, 2), प्रारंभ (:, 3), समाप्त होता है (:, 1), समाप्त होता है (:, 2), समाप्त होता है (:, 3), 0) ' –

+0

स्केल तर्क के लिए धन्यवाद मार्टिन। लेकिन क्लिवर 3 में तीरहेड Matlab फ़ाइल एक्सचेंज से arrow.m की तुलना में बहुत अच्छा नहीं लग रहा है। – Aamir

2

मुझे 3D में ऐसा करने का कोई तरीका नहीं है, लेकिन 2D में आप compass कमांड का उपयोग कर सकते हैं।

6

मैं जो सच परिमाण और दिशा के साथ वैक्टर ड्राइंग का इस उद्देश्य के लिए एकदम सही है MATLAB Central पर इस arrow(start, end) समारोह पाया।

16

मैं Aamir से सहमत हूं कि से arrow.mMathWorks File Exchange पर एक बहुत अच्छा विकल्प है। आप वर्णन करने के लिए उपयोग कर सकते हैं different methods of vector addition तो जैसे:

  • टिप-टू-पूंछ विधि:

    o = [0 0 0]; %# Origin 
    a = [2 3 5]; %# Vector 1 
    b = [1 1 0]; %# Vector 2 
    c = a+b;  %# Resultant 
    arrowStarts = [o; a; o];  %# Starting points for arrows 
    arrowEnds = [a; c; c];   %# Ending points for arrows 
    arrow(arrowStarts,arrowEnds); %# Plot arrows 
    
  • चतुर्भुज विधि:

    o = [0 0 0]; %# Origin 
    a = [2 3 5]; %# Vector 1 
    b = [1 1 0]; %# Vector 2 
    c = a+b;  %# Resultant 
    arrowStarts = [o; o; o];  %# Starting points for arrows 
    arrowEnds = [a; b; c];   %# Ending points for arrows 
    arrow(arrowStarts,arrowEnds); %# Plot arrows 
    hold on; 
    lineX = [a(1) b(1); c(1) c(1)]; %# X data for lines 
    lineY = [a(2) b(2); c(2) c(2)]; %# Y data for lines 
    lineZ = [a(3) b(3); c(3) c(3)]; %# Z data for lines 
    line(lineX,lineY,lineZ,'Color','k','LineStyle',':'); %# Plot lines 
    
3

मैं इसे ऐसा किया रास्ता,

2 डी

% vectors I want to plot as rows (XSTART, YSTART) (XDIR, YDIR) 
rays = [ 
    1 2 1 0 ; 
    3 3 0 1 ; 
    0 1 2 0 ; 
    2 0 0 2 ; 
] ; 

% quiver plot 
quiver(rays(:,1), rays(:,2), rays(:,3), rays(:,4)); 

3 डी

% vectors I want to plot as rows (XSTART, YSTART, ZSTART) (XDIR, YDIR, ZDIR) 
rays = [ 
    1 2 0 1 0 0; 
    3 3 2 0 1 -1 ; 
    0 1 -1 2 0 8; 
    2 0 0 0 2 1; 
] ; 

% quiver plot 
quiver3(rays(:,1), rays(:,2), rays(:,3), rays(:,4), rays(:,5), rays(:,6)); 

-1
  % draw simple vector from pt a to pt b 
      % wtr : with respect to 
      scale=0;%for drawin vectors with true scale 
      a = [10 20 30];% wrt origine O(0,0,0) 
      b = [10 10 20];% wrt origine O(0,0,0) 

      starts=a;% a now is the origine of my vector to draw (from a to b) so we made a translation from point O to point a = to vector a 
      c = b-a;% c is the new coordinates of b wrt origine a 
      ends=c;% 
      plot3(a(1),a(2),a(3),'*b') 
      hold on 
      plot3(b(1),b(2),b(3),'*g') 

      quiver3(starts(:,1), starts(:,2), starts(:,3), ends(:,1), ends(:,2), ends(:,3),scale);% Use scale = 0 to plot the vectors without the automatic scaling. 
      % axis equal 
      hold off 
संबंधित मुद्दे