Wrong direction of E-Field lines using "Quiver Function" in a program to solve Simple Laplace Problem.

조회 수: 4 (최근 30일)
This is my program to solve a simple laplace problem where a Voltage of 100V is applied at the top and all other bounderies are 0V. The Matrix outputs the correct values (in var "z"). And the potential distribution seems right. The Problem is that when I use the quiver function to plot the E-Field lines then they originate from the bottom boundary (at 0V) and end at sides and the Top. But the Fields should originate from the top at (100v) and end at the sides and the bottom. I can't figure out what went wrong so any help would be appreciated. Thanks.
%array
u = zeros(50);
u(1,:)=100;
z = u;
%loop
for i =1:500
for i = 2: size(z,1)-1;
for j = 2 : size(z,1)-1
z(i,j) = (z(i-1,j)+z(i+1,j)+z(i,j-1)+z(i,j+1))/4;
end
end
% getframe
figure(1)
end
imagesc(z);
figure(2)
[ex,ey] = gradient(z);
axis xy
quiver(-ex,-ey,3);

채택된 답변

Star Strider
Star Strider 2015년 8월 27일
Note the y-axis orientation between the image plot and the quiver call. If you use contourf instead of imagesc, they match. If you want zero to start at the top of the plot for both, set the 'YDir' property for each figure if you use contourf, and the quiver plot if you use imagesc:
set(gca, 'YDir','reverse')
If you want to overplot the quiver arrows on top of the first plot, use the hold function.
  댓글 수: 2
Riyasat
Riyasat 2015년 8월 27일
It worked thanks a lot. And thanks for the explanation too. Can you please explain why this discrepency between Imagesc and Contour functions?
Star Strider
Star Strider 2015년 8월 27일
My pleasure.
I don’t know why images start in the upper left corner, but the image convention seems to have existed before MATLAB, and follows earlier graphics conventions that I remember from the 1970s. Plots — including contour — always started in the lower left, again by convention.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by