%
%   Book: MATLAB-Based Electromagnetics (Pearson Prentice Hall)
%   Author: Branislav M. Notaros
%   Instructor Resources
%   (c) 2011
%
%   This MATLAB code or any part of it may be used only for 
%   educational purposes associated with the book
%
%
%


%   Field from potential, in three coordinate systems


clear all;
close all;

a = input('\nChoose coordinate system (1)Cartesian, (2)Spherical ,(3)Cylindrical : ');
switch a
    case 1
        syms x y z
        fprintf('\nVariables in Cartesian system are: x, y and z');
        V = input('\nGive analytic formula for potential depending on these variables: ');
        [Ex, Ey, Ez] =  gradCar(-V); 
        E = [Ex, Ey, Ez];
        fprintf('Field is given by formula');
        pretty(E);
    case 2
        syms r theta phi
        fprintf('\nVariables in Spherical system are: r, theta and phi');
        V = input('\nGive analytic formula for potential depending on these variables: ');
        [Er, Et, Ep] =  gradSph(-V);
        E = [Er, Et, Ep];
        fprintf('Field is given by formula');
        pretty(E);
    case 3
        syms r phi z
        fprintf('\nVariables in Cylindrical system are: r, phi and z');
        V = input('\nGive analytic formula for potential depending on these variables: ');
        [Er, Ep, Ez] =  gradCyl(-V);
        E = [Er, Ep, Ez];
        fprintf('Field is given by formula');
        pretty(E);
    otherwise
        fprintf('Incorrect input!');
end;