function [PfunPx]=partials(fun,x,dx)
% function [PfunPx]=partials(fun,x,dx)
% Given the nonlinear functions
% 	y = fun(x)
% Linearize them about x
% Use small perturbations dx in x
%
% PfunPx=partial of fun with respect to x

[n1,m1]=size(x);
n=max(n1,m1);
PfunPxPlus=zeros(size(x));
PfunPxMinus=zeros(size(x));
PfunPx=zeros(size(x));
y0=feval(fun,x);
for i=1:n
        x1=x;
        x1(i)=x1(i) + dx(i);
        y1=feval(fun,x1);
        dy=y1 - y0;
        dy=dy/dx(i);
        PfunPxPlus(i)=dy;
end
for i=1:n
        x1=x;
        x1(i)=x1(i) - dx(i);
        y1=feval(fun,x1);
        dy=-(y1 - y0);
        dy=dy/dx(i);
        PfunPxMinus(i)=dy;
end
PfunPx=(PfunPxPlus+PfunPxMinus)/2;
