%Finite difference method with Poisson's equation
clear all;
clc;
d=0.001;
n=50;
h=d/(n-1);
ro0=1e-4;
e=8.854e-12;
A=diag(-2.*ones(1,n-2));
A1=diag(ones(1,n-3),1);
A2=diag(ones(1,n-3),-1);
A=A+A1+A2;
b=((h*h)*(-ro0/e)*ones(1,n-2));
b(end)=(h*h)*(-ro0/e)-1;

V=inv(A)*b';
V=[0; V; 1];
y=linspace(0,d,length(V));
plot(y,V);
xlabel('Distance (in cm)')
ylabel('Voltage (in volt)')
grid on