Ask Your Question

Evaluate partial derivative

asked 2020-10-25 16:43:47 -0600

jgroh gravatar image

updated 2020-10-26 12:42:08 -0600

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} $

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

edit retag flag offensive close merge delete


Welcome to Ask Sage!

Thank you for your question!

slelievre gravatar imageslelievre ( 2020-10-26 10:19:52 -0600 )edit

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

slelievre gravatar imageslelievre ( 2020-10-26 10:20:03 -0600 )edit


(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.

slelievre gravatar imageslelievre ( 2020-10-26 12:51:31 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2020-10-28 08:54:26 -0600

Florentin Jaffredo gravatar image

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})


$\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}}$

edit flag offensive delete link more


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

jgroh gravatar imagejgroh ( 2020-10-29 17:45:11 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2020-10-25 16:43:47 -0600

Seen: 67 times

Last updated: Oct 28 '20