clear all Q1=4e-12; Q2=-2e-12; e0=8.854e-12; k=1/(4*pi*e0); r1=[1, 0, 1]*1e-2; r2=[-1,0,-1]*1e-2; X=[-3:0.1:3]*1e-2; len=length(X); Y=zeros(1,len); Z=Y; P=[X' Y' Z']; %tvorimo matriko s koordinatami tock P(x,y,z) P(1,:) % tako zapišemo prvi vektor for i=1:len RP1(i,:)=(P(i,:)-r1); ERP1(i,:)=k*Q1*RP1(i,:)/(RP1(i,:)*RP1(i,:)')^3; RP2(i,:)=(P(i,:)-r2); ERP2(i,:)=k*Q2*RP2(i,:)/(RP2(i,:)*RP2(i,:)')^3; end ERP1(:,1); % x komponenta polja, ki ga povzroca elektrina Q2 ERP2(:,1); % x komponenta polja, ki ga povzroca elektrina Q2 E=ERP1 + ERP2; for i=1:len Eabs(i)=sqrt(E(i,1)^2+E(i,2)^2+E(i,3)^2); end Eabs; figure subplot(2,1,1),plot(X,E(:,3)) grid on; xlabel(' x [m]'); ylabel('Ex [V/m]'); subplot(2,1,2),plot(X,Eabs) grid on; xlabel(' x [m]'); ylabel('AbsE [V/m]');