Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
It appears that the tuple syntax works like this: (variable index, order of derivative) Where something like: base = poly(x*y**2 + x, x, y) deriv_mysterious5 = base.diff((0,1)) print('deriv_mysteri...
Answer
#3: Post edited
- It appears that the tuple syntax works like this:
- `(variable index, order of derivative)`
- Where something like:
- ```
- base = poly(x*y**2 + x, x, y)
- deriv_mysterious5 = base.diff((0,1))
- print('deriv_mysterious5 is', deriv_mysterious5)
- ```
- Means: "Take first derivative of `base` with respect to symbol[0]", in this case symbol 0 is x.
- - I was not able to find information on how sympy determines which symbol is symbol 0.
- I think I would recommend the alternative syntax instead:
- ```
- base.diff(<symbol>)
- ```
- e.g.,
- ```
- base.diff(x)
- ```
- Though, interestingly, it seems that for higher order derivatives, `poly.diff` has some behavior that seems to differ from `diff(expr,...)` as seen on the [Calculus](https://docs.sympy.org/latest/tutorial/calculus.html#derivatives) page.
- This syntax works:
- ```
- base.diff(y, y)
- ```
- I was not able to get this syntax working:
- ```
- base.diff(y, 2)
- ```
- But a slightly modified version of this does work,
- ```
base.diff((y, 3))- ```
- It appears that the tuple syntax works like this:
- `(variable index, order of derivative)`
- Where something like:
- ```
- base = poly(x*y**2 + x, x, y)
- deriv_mysterious5 = base.diff((0,1))
- print('deriv_mysterious5 is', deriv_mysterious5)
- ```
- Means: "Take first derivative of `base` with respect to symbol[0]", in this case symbol 0 is x.
- - I was not able to find information on how sympy determines which symbol is symbol 0.
- I think I would recommend the alternative syntax instead:
- ```
- base.diff(<symbol>)
- ```
- e.g.,
- ```
- base.diff(x)
- ```
- Though, interestingly, it seems that for higher order derivatives, `poly.diff` has some behavior that seems to differ from `diff(expr,...)` as seen on the [Calculus](https://docs.sympy.org/latest/tutorial/calculus.html#derivatives) page.
- This syntax works:
- ```
- base.diff(y, y)
- ```
- I was not able to get this syntax working:
- ```
- base.diff(y, 2)
- ```
- But a slightly modified version of this does work,
- ```
- base.diff((y, 2))
- ```
#2: Post edited
- It appears that the tuple syntax works like this:
- `(variable index, order of derivative)`
- Where something like:
- ```
- base = poly(x*y**2 + x, x, y)
- deriv_mysterious5 = base.diff((0,1))
- print('deriv_mysterious5 is', deriv_mysterious5)
- ```
- Means: "Take first derivative of `base` with respect to symbol[0]", in this case symbol 0 is x.
- - I was not able to find information on how sympy determines which symbol is symbol 0.
- I think I would recommend the alternative syntax instead:
- ```
- base.diff(<symbol>)
- ```
- e.g.,
- ```
- base.diff(x)
- ```
Though, interestingly, it seems that for higher order derivatives, only this syntax is supported:- ```
base.diff(x, x, x)- ```
- I was not able to get this syntax working:
- ```
base.diff(x, 3)```
- It appears that the tuple syntax works like this:
- `(variable index, order of derivative)`
- Where something like:
- ```
- base = poly(x*y**2 + x, x, y)
- deriv_mysterious5 = base.diff((0,1))
- print('deriv_mysterious5 is', deriv_mysterious5)
- ```
- Means: "Take first derivative of `base` with respect to symbol[0]", in this case symbol 0 is x.
- - I was not able to find information on how sympy determines which symbol is symbol 0.
- I think I would recommend the alternative syntax instead:
- ```
- base.diff(<symbol>)
- ```
- e.g.,
- ```
- base.diff(x)
- ```
- Though, interestingly, it seems that for higher order derivatives, `poly.diff` has some behavior that seems to differ from `diff(expr,...)` as seen on the [Calculus](https://docs.sympy.org/latest/tutorial/calculus.html#derivatives) page.
- This syntax works:
- ```
- base.diff(y, y)
- ```
- I was not able to get this syntax working:
- ```
- base.diff(y, 2)
- ```
- But a slightly modified version of this does work,
- ```
- base.diff((y, 3))
- ```
#1: Initial revision
It appears that the tuple syntax works like this: `(variable index, order of derivative)` Where something like: ``` base = poly(x*y**2 + x, x, y) deriv_mysterious5 = base.diff((0,1)) print('deriv_mysterious5 is', deriv_mysterious5) ``` Means: "Take first derivative of `base` with respect to symbol[0]", in this case symbol 0 is x. - I was not able to find information on how sympy determines which symbol is symbol 0. I think I would recommend the alternative syntax instead: ``` base.diff(<symbol>) ``` e.g., ``` base.diff(x) ``` Though, interestingly, it seems that for higher order derivatives, only this syntax is supported: ``` base.diff(x, x, x) ``` I was not able to get this syntax working: ``` base.diff(x, 3) ```