symbolic icon indicating copy to clipboard operation
symbolic copied to clipboard

[wip] New Diff2

Open latot opened this issue 7 years ago • 5 comments

Hi!, it feels to much time, well here i have a rewrite to the diff function, the reasons are simple, first, when we have a function with more than one var the diff command send the partial derivation only of the first founded var, ex:

>> syms f(g, h)
>> diff(f)
ans(g, h) = (symfun)

  ∂          
  ──(f(g, h))
  ∂h         

i think this is really bad, theoretically the diff should use the chain rule and apply it, but actually we can't do that, at least while this issue is open: https://github.com/cbm755/octsympy/issues/519 So, i think its better have a warning/error instead a wrong calc, (and start searching the problem etc).

I try keep the main functions of diff, so the new syntax would be :

diff(FUNCTION, VAR1, GRADE OF VAR1, VAR2, GRADE OF VAR2 .....)

this code recognize symbols on functions if you don't send the first derive var, and if the first arg is a number is derived in that grade, one of the differences with the actual diff is this:

actual diff:

>> syms x
>> f=sin(x)
f = (sym) sin(x)
>> diff(f, 2, x)
ans = (sym) -sin(x)

new diff

>> syms x
>> f=sin(x)
f = (sym) sin(x)
>> diff(f, 2, x)
ans = (sym) -cos(x)

basically the new diff(f, 2, x) menas, derive f two times in x, then derive it in x again. I think include the chain rule but i will leave that to sympy: https://github.com/sympy/sympy/issues/11573

Thx. Cya.

latot avatar Sep 01 '16 21:09 latot

mm, reading this will break compatibility with SMT, so this don't is an option D: other pr!

latot avatar Sep 01 '16 22:09 latot

Thinking, the diff of SMT diverge of the diff of SymPy, maybe can be good idea move this diff to diff2 to better compatibility with SymPy.

In what diverge? diff of sympy use chain rule, while diff of SMT only partial derive of the first founded var.

latot avatar Sep 01 '16 23:09 latot

ups, don't is a octave problem, my bad again, i notice this now, the actual diff don't its compatible with octave D: that should be fixed! lets work a little more in this.

latot avatar Sep 05 '16 13:09 latot

Regarding your specific example: that does look wrong, I think symvar should choose g as the variable to differentiate w.r.t.; I've filed #550.

cbm755 avatar Sep 14 '16 20:09 cbm755

Now: I don't understand what you're trying to fix. diff(f, 2, x) is old legacy SMT stuff as discussed elsewhere. But it is supposed to calculate the 2nd partial wrt x: not a third partial.

Was there something else you're trying to address here?

cbm755 avatar Sep 14 '16 20:09 cbm755