Java Scrap Book  

Java Scrap Book > MATLAB > potential

potential

% Electric Potential
function lab3
infinite=160;
V=zeros(40,40);
Xmin=0;
Xmax=1;
Ymin=0;
Ymax=1;
StepsizeX= (Xmax-Xmin)/(39);
StepsizeY=(Ymax-Ymin)/(39);
[xmesh,ymesh] = meshgrid(Xmin:StepsizeX:Xmax,Ymin:StepsizeY:Ymax);
for j=1:40
for i=1:40
x=Xmin+(i-1)*StepsizeX;
y=Ymin+(j-1)*StepsizeY;
for n=1:infinite
V(j,i)=V(j,i)+(2-2*(-1)^n)*sinh(n*pi*y)*sin(n*pi*x)/(n*pi*sinh(n*pi));
end
end
end

contour(xmesh,ymesh,V);
xlabel('x(m)');
ylabel('y(m)');
title('Surface of the voltage in the region 0<x<1 and 0<y<1');
figure;
contour(xmesh,ymesh,V);
[px,py] = gradient(V);
hold on,
quiver(xmesh,ymesh,-px,-py,3),
hold off,
xlabel('x(m)');
ylabel('y(m)');
title('Electric field lines in the region <x<1 and 0<y<1');
end


Copyright © 2013-2018

javascrapbook.com is a computer science content service should not be treated as the publisher or speaker of any information provided by another Computer Science content provider.

Contact email: help@javascrapbook.com