Gradient vector field not perpendicular to contour map

6 ビュー (過去 30 日間)
Cole Butler
Cole Butler 2017 年 10 月 10 日
コメント済み: Cole Butler 2017 年 10 月 16 日
I have the following code:
function [ ] = kermack( I0,r,p,c,N,numSteps )
I(1)=I0;
S(1)=N-I0;
for t = 1:numSteps % construct I and S vectors
I(t+1) = I(t) + (p*c*I(t)*S(t) - r*I(t));
S(t+1) = S(t) - p*c*I(t)*S(t);
end
% create contour
x = min(I):0.2:max(I);
y = min(S):0.2:max(S);
[xx,yy] = meshgrid(x,y);
zz = xx + yy - (r/(p*c))*log(yy); % f(I,S)
[DX,DY] = gradient(zz);
figure % new window
contour(xx,yy,zz)
hold on % superimpose graphs
scale=10; % to make the arrows visible
quiver(xx,yy,DX,DY,scale) % vector field of f(I,S)
xlim([0 60]); % set bounds on the window
ylim([0,80]);
xlabel('I(t) (infected/infectious population)');
ylabel('S(t) (susceptible population)');
hold off
Now, as made clear by the title of my question, the generated gradient vector field doesn't seem to be perpendicular with the superimposed contour mapping. How can this be? What am I doing wrong?
  5 件のコメント
KSSV
KSSV 2017 年 10 月 12 日
Give the input directly.....how did you run code and what you expect?
Cole Butler
Cole Butler 2017 年 10 月 16 日
In response to the previous comments, I have attached an example of the code. This is the output of kermack() for p=0.05, c=0.2, r=0.2, numSteps = 50, N=100, I0=10. Clearly, the solid blue lines are the contour lines. When you zoom in, you can see that the gradient field is not perpendicular to the contour lines.
<<
>>

サインインしてコメントする。

採用された回答

David Goodmanson
David Goodmanson 2017 年 10 月 16 日
Hi Cole,
I believe this is an artifact of the zoom process. If you zoom in by drawing a rectangle, the axes get scaled differently and right angles no longer appear to be right angles. If you add
axis equal
at the end of the code and then zoom in simply by repeated clicking on a point on a contour line (which does 2x on each axis), the results appear to be good.
  1 件のコメント
Cole Butler
Cole Butler 2017 年 10 月 16 日
That did it! Thank you very much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by