Effacer les filtres
Effacer les filtres

Using quiver to vary magnitudes of the vector

4 vues (au cours des 30 derniers jours)
yashvini shukla
yashvini shukla le 16 Mai 2020
Commenté : darova le 17 Mai 2020
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 commentaire
darova
darova le 17 Mai 2020
Here is the problem
But there is no need in such operations. YOu are calculating ratio
ratio = oldmag.*mag./oldmag;
ratio = mag;

Connectez-vous pour commenter.

Réponses (1)

darova
darova le 16 Mai 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 commentaires
darova
darova le 16 Mai 2020
Maybe problem is in quiver scaling
what about this
f = quiver(xx,yy,-dy,dx,'g',4) % plotting the components
yashvini shukla
yashvini shukla le 16 Mai 2020
i tried that, its not working...

Connectez-vous pour commenter.

Catégories

En savoir plus sur Vector Fields 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!

Translated by