# Evaluate partial derivative

I have a function B(x,y) and I have an expression f in which this function appears.

B(x, y) = function('B')(x, y)
f = B(v_m, v)*theta/(B(v_m,v) + theta)
g = f.diff(v_m)


I now have an expression, g, which involves the partial derivative of B w.r.t v_m , and I would like to evaluate this entire expression, including the partial derivative, at v_m == v.

I can do g.substitute(v_m == v) or at(g, v_m == v) but both of these just change the expression to give me the partial derivative of B with respect to v, which is not what I want.

Do I need to explicitly define that the partial derivative is a function somehow? I would like to be able to use this expression I have containing the partial derivative and evaluate it as if it is a function, where the output contains the value of the derivative of B w.r.t. v_m, evaluated at the input, in the context of the rest of the expression evaluated at that input.

In other words, in the latex representation, I'd like the notation to preserve the expression of the partial derivative and then have the vertical bar on the right hand side to indicate it's being evaluated at a particular point, or in this case, another variable. Here is the latex representation that I'm looking for, for the part of the expression involving the partial derivative:

$$\frac{\partial}{\partial v_{m}}B\left(v_{m}, v\right) \Bigr\rvert_{v_m = v}$$

edit retag close merge delete

( 2020-10-26 16:19:52 +0200 )edit

Please provide an explicit example of B(x, y) that can be copy-pasted in a fresh Sage session to explore the question.

( 2020-10-26 16:20:03 +0200 )edit

@jgroh

(I'm not sure why but the latex rendering is appearing strangely despite that in my preview of the post it appears correctly)

Indeed, there are some MathJax problems at Ask Sage. Thanks for calling attention on this one.

( 2020-10-26 18:51:31 +0200 )edit

To fix the LaTeX on Ask Sage, replace \ by \\, so type \\frac instead of \frac etc.

( 2021-01-27 13:40:41 +0200 )edit

Sort by » oldest newest most voted

When you do g(v_m=v) or g.subs(v_m=v) I think you get the correct answer:

$\frac{\theta D_{0}\left(B\right)\left(v, v\right)}{\theta + B\left(v, v\right)} - \frac{\theta B\left(v, v\right) D_{0}\left(B\right)\left(v, v\right)}{{\left(\theta + B\left(v, v\right)\right)}^{2}}$

$D_0(B)$ is the partial derivative of B with respect to the first argument ($v_m$ in your case), and this partial derivative is then evaluated at $(v,v)$.

If all you want to do is change the appearance of the partial derivative, you can do it by substituting another variable, for which you specify the latex representation:

D = sage.symbolic.operators.FDerivativeOperator
dB = var('dB', latex_name=r'{\frac{\partial B(v_m, v)}{\partial v_m}}_{|v_m=v}')
g(v_m=v).subs({D(B, [0])(v, v): dB})


Result:

$\frac{{{\frac{\partial}{\partial v_m}} B(v_m, v)_{|v_m=v}} \theta}{\theta + B\left(v, v\right)} - \frac{{{\frac{\partial}{\partial v_m}} B(v_m, v)_{|v_m=v}} \theta B\left(v, v\right)}{{\left(\theta + B\left(v, v\right)\right)}^{2}}$

more

Okay, I see now that it is working. I was confused by the D notation. Thank you!

( 2020-10-29 23:45:11 +0200 )edit