function Control1_3( model )
% Solution to problem 3, control 1, Nov.2016
% J.M.Soler

% Set parameters
dx = 0.02;               % x coordinate interval (m)
if model=='A'
  q = -1.2e-9;           % point charge (C)
  rq = [8.0;-1.3;2.0];   % charge coordinates (m)
  xi = 3.5;              % x initial coordinate of test point (m)
  xf = 10.0;             % x final coordinate of test point (m)
elseif model=='B'
  q = 2.8e-9;
  rq = [-3.5;2.3;1.0];
  xi = -6.5;
  xf = 1.5;
elseif model=='C'
  q = -3.5e-9;
  rq = [-7.5;1.3;-2.3];
  xi = -10.0;
  xf = -1.0;
elseif model=='D'
  q = 0.7e-9;
  rq = [2.7;0.3;-1.1];
  xi = -1.5;
  xf = 8.0;
else
  error(['ERROR: invalid model = ',model])
end

% Find coordinates along segment
x = (xi:dx:xf);
nx = numel(x);
r = [x;zeros(2,nx)];

% Find electric field and potential
for ix = 1:nx
  [E(:,ix),V(ix)] = CampoPotencial(q,rq,r(:,ix));
end

% Plot electric field
figure(11)
plot(x,E(1,:),x,E(2,:),x,E(3,:),x,sqrt(sum(E.^2)))
grid on
legend('E_x','E_y','E_z','|E|')
xlabel('x (m)')
ylabel('E (V/m)')
title('Electric field')

% Plot electric potential
figure(12)
plot(x,V)
grid on
xlabel('x (m)')
ylabel('V (V)')
title('Electric potential')
