Ask Your Question
1

Evaluate partial derivative

asked 2020-10-25 22:43:47 +0100

jgroh gravatar image

updated 2021-01-27 13:43:24 +0100

slelievre gravatar image

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 flag offensive close merge delete

Comments

Welcome to Ask Sage!

Thank you for your question!

slelievre gravatar imageslelievre ( 2020-10-26 16:19:52 +0100 )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 16:20:03 +0100 )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.

slelievre gravatar imageslelievre ( 2020-10-26 18:51:31 +0100 )edit

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

slelievre gravatar imageslelievre ( 2021-01-27 13:40:41 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-10-28 14:54:26 +0100

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

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

edit flag offensive delete link more

Comments

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

jgroh gravatar imagejgroh ( 2020-10-29 23:45:11 +0100 )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

Stats

Asked: 2020-10-25 22:43:47 +0100

Seen: 940 times

Last updated: Jan 27 '21