
Using quiver to vary magnitudes of the vector
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
darova
el 17 de Mayo de 2020
Here is the problem

But there is no need in such operations. YOu are calculating ratio
ratio = oldmag.*mag./oldmag;
ratio = mag;
Respuestas (1)
darova
el 16 de Mayo de 2020
- 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 comentarios
darova
el 16 de Mayo de 2020
Maybe problem is in quiver scaling
what about this
f = quiver(xx,yy,-dy,dx,'g',4) % plotting the components
Ver también
Categorías
Más información sobre Vector Fields en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!