drawing function phase space and draw the associated vector field

조회 수: 1 (최근 30일)
Elinor Ginzburg
Elinor Ginzburg 2019년 12월 22일
댓글: Elinor Ginzburg 2019년 12월 27일
hello,
I'm trying to draw the following in phas-space, and to show the vector field, but I'm getting some very strange results. can anyone please explain to me how can I draw this function in phase-space and how to show the vector field?
I'm trying to plot elevation lines where H=constant, and to show the associated vector field.
my attempt:
m=1; R=1;Om=1;g=10;
x= linspace(-100,100,100000);
y=sqrt(m*(R^2)*(Om^2)*(sin(x).^2)-2*(m^2)*g*(R^3)*(cos(x)));
quiver(x,y);
thank you!
  댓글 수: 6
David Goodmanson
David Goodmanson 2019년 12월 26일
편집: David Goodmanson 2019년 12월 27일
Hi Elinor,
there are a couple of things here. The idea is not to calculate p as a function of theta in some manner, as you appear to be doing. Rather, both theta and p are independent variables. The idea is to set up a 2d plane with all possible pairs of values for p and theta, and then calculate H in the theta,p plane. Meshgrid allows you to do that, so meshgrid needs to be done before calculatiing H. And H is simply the expression you provided in the original question, except there is a mistake. The term involving Om^2 should have a + sign..
m = 2;
R = 5;
Om = 0;
g = 9.8;
thetavalues = -3*pi:.1:3*pi;
Lvalues = (-200:.2:200);
[theta,L] = meshgrid(thetavalues,Lvalues);
H = L.^2/(2*m*R^2) + (1/2)*m*R^2*Om^2*sin(theta).^2 - m*g*R*cos(theta);
Using p for the momentum is perfectly acceptable, but since the momentum in this problem is the angular momentum, I changed p to L.
Now you can do a contour plot with theta,L and H. The plot does not really provide enough contour lines, but if you take a look at 'help contour' you can see how to provide more contour lines with one more argument to the contour function. It helps to use 'grid on' just after the contour command, also 'colorbar'.
With Om = 0 you should see stable equilibrium points at theta = -2*pi, 0 and 2*pi, an ordinary pendulum at the low point of its swing. As Om is increased, eventually you should see more equilibrium points appear, at theta values corresponding to the pendulum at the top of its swing.
Elinor Ginzburg
Elinor Ginzburg 2019년 12월 27일
thank you very much! I understand now how to use it. I'm still new to matlab, so sometimes it's hard to search the documentation for something specific. thank you again for your help!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by