syms xyep0
E = [x^2 y^2];
rho = divergence(E,[x y])*ep0
rho =
ep0 = 1을 사용하여 -2 < x < 2와 -2 < y < 2에 대해 전기장과 전하 밀도를 시각화합니다. meshgrid를 사용하여 x 값과 y 값의 그리드를 만듭니다. subs를 사용해 그리드 값을 대입하여 전기장과 전하 밀도의 값을 구합니다. subs에 대한 입력값으로 셀형 배열을 사용하여 전하 밀도 rho에 그리드 값 xPlot과 yPlot을 동시에 대입합니다.
rho = subs(rho,ep0,1);
v = -2:0.1:2;
[xPlot,yPlot] = meshgrid(v);
Ex = subs(E(1),x,xPlot);
Ey = subs(E(2),y,yPlot);
rhoPlot = double(subs(rho,{x,y},{xPlot,yPlot}));
quiver를 사용하여 전기장을 플로팅합니다. contour를 사용하여 전하 밀도를 겹쳐 놓습니다. 등고선이 전하 밀도의 값을 나타냅니다.
quiver(xPlot,yPlot,Ex,Ey)
hold on
contour(xPlot,yPlot,rhoPlot,'ShowText','on')
title('Contour Plot of Charge Density Over Electric Field')
xlabel('x')
ylabel('y')
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.