Using quiver to vary magnitudes of the vector
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi there,
I need to change the magnitude of each point on a quiver plot. Here is the code;
py= 49.35/Dmm;
px = (0.3125*Dmm)/Dmm;
g = streamline(X,Y,vx,vy,px,py); %plotting the upper line
x = g.XData;
y = g.YData;
xx = x(ind);
yy = y(ind);
dx = gradient(xx)
dy = gradient(yy)
[dx,dy] = magvec(9, dx ,dy) %Custom function to change magnitude
p = plot(xx,yy,'r') %stream line
f = quiver(xx,yy,-dy,dx,'g') % plotting the components
the -dy, dx is to plot the vectors outward to the line. i'm not sure how quiver works, but the problem is that the result plotted isn't tangent to the stream line after i pass the dx and dy values through the magvec function, but is tangent and works correctly when i dont pass it through the magvec function. The error could be in magvec, and there are some redundancies in the function (could have multiplied dx by mag directly), but otherwise nothing (that i can see) should cause an error.
i'd really appreciate any help here.
this figure shows the plot after using magnitude as 2 for the upper contour, which should ideally be larger than the lower one.
the function that i used to change the magnitude:-
function [x,y] = magvec(mag, dx ,dy)
oldmag = (dx.^2+dy.^2).^0.5;
newmag = oldmag.*mag;
ratio = newmag/oldmag;
x = dx.*ratio;
y = dy.*ratio;
end
댓글 수: 1
darova
2020년 5월 17일
Here is the problem
But there is no need in such operations. YOu are calculating ratio
ratio = oldmag.*mag./oldmag;
ratio = mag;
답변 (1개)
darova
2020년 5월 16일
- but the problem is that the result plotted isn't tangent to the stream
Why did you change dy and dx order here?
f = quiver(xx,yy,-dy,dx,'g') % plotting the components
댓글 수: 3
darova
2020년 5월 16일
Maybe problem is in quiver scaling
what about this
f = quiver(xx,yy,-dy,dx,'g',4) % plotting the components
참고 항목
카테고리
Help Center 및 File Exchange에서 Vector Fields에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!