here is the problem that I am having variables var1(time,lev,lat,lon) and var2(time,lev,lat,lon) and I want to differentiate var1 w.r.t. var2 i.e. d(var1)/d(var2).
Before discussing how to implement it in Ferret, we need to make it clear what you mean by d(var1)/d(var2) in a multidimensional space.
To illustrate the problem, let's consider 2D variables var1(x,y) and var2(x,y). Along a zonal section at a fixed latitude y0, we observe how these variables change:
var1(x + dx, y0) = var1(x, y0) + [∂(var1)/∂x] dx,
var2(x + dx, y0) = var1(x, y0) + [∂(var2)/∂x] dx.
So the changes are
d(var1) = [∂(var1)/∂x] dx,
d(var2) = [∂(var2)/∂x] dx.
Along this zonal section, therefore,
d(var1)/d(var2)
= {[∂(var1)/∂x] dx} / {[∂(var2)/∂x] dx}
= [∂(var1)/∂x] / [∂(var2)/∂x]
This result is the same as a 1D case. You can easily implement this in Ferret using the partial derivative operator(s) in the x direction.
Similarly, along a meridional, you get d(var1)/d(var2) = [∂(var1)/∂y] / [∂(var2)/∂y].