%
%   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
%
%
%


%    Symbolic divergence in spherical coordinates


function F = divSph(fr,ft,fp)
syms r phi theta
Fr = diff(r^2*fr,r);
Fp = diff(fp,phi);
Ft = diff(sin(theta)*ft,theta);
F = 1/r^2*Fr + 1/(r*sin(theta))*Fp + 1/(r*sin(theta))*Ft;