jiggzson/nerdamer

nerdamer.diff("x * sqrt(y)","x") function returning incorrect expression during partial differentiation if the constant term in the equation (in this case sqrt(y)) is under square root

sg13041995 opened this issue · 1 comments

nerdamer.diff("y * sqrt(x)","y") returns => (sqrt(x^0.5));

But is should return (sqrt(x)) or (x)^0.5

So, I have conducted multiple tests and found out that, this issue is occurring if,
"The constant term during partial differentiation, in the equation or function is under square-root"

Example:
f(x,y) = the expression = y * sqrt(x)
f(x,y) = the expression = y / sqrt(x)

In this case if we try nerdamer.diff("y * sqrt(x)","y") or nerdamer.diff("y/sqrt(x)","y") where sqrt(x) is a constant, then output is coming wrong.
But it perfectly works if nerdamer.diff("y*sqrt(x)","x") where y is constant now and we are differentiating w.r.t x.

It will again throw wrong out put => 0.5*sqrt(x^0.5)*y^(-0.5) if we try nerdamer.diff("sqrt(y)*sqrt(x)", "y") as sqrt(x) in the equation was a constant in the context of the partial differentiation.

The major mistake is in the output equation that I have observed is, where it should throw sqrt(x) it is throwing sqrt(x^0.5).

In my vector field plotter and curl divergence calculator project I have applied a get around to make things work.

In my curl equation where we do (dq/dx - dp/dy) I know that in in q expression any y term will going to be constant and in p expression the x term.

So, if we have any y term under square root in q expression , I replaced that with Q. So, now in the q equation, in the place of sqrt(y) there will be Q. Now, nerdamer can handle it properly and treat it as proper constant.

After the solution, I have converted Q back into sqrt(y).

I did the same for p expression and also for the divergence equation separately.

Things are working fine for me now.

You can check my code as well.
divergence(), curl() functions in mainsketch.js under the provided commit.

https://github.com/sg13041995/2D_Vector_field_plotter_
sg13041995/VectorFieldPlotter@1e5bdb9

You can check out my app as well.
https://vector-field-plotter-e6668.web.app/

Thank you.
I hope this will be somewhat helpful.