Matthias Geier
unread,Jun 26, 2018, 8:31:32 AM6/26/18Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sy...@googlegroups.com
Dear list.
Sorry for the strange title, I couldn't come up with anything more
meaningful ...
I'm working with non-uniform cubic splines and I created a simple
polynomial where the input t in the range [t0, t1] is mapped to the
range [0, 1]:
>>> import sympy as sp
>>> t, t0, t1 = sp.symbols('t t:2')
>>> coefficients = sp.Matrix(sp.symbols('a:4')[::-1])
>>> p = sp.Matrix([t**3, t**2, t, 1]).dot(coefficients).subs(t, (t - t0) / (t1 - t0))
>>> p
a0 + a1*(t - t0)/(-t0 + t1) + a2*(t - t0)**2/(-t0 + t1)**2 + a3*(t -
t0)**3/(-t0 + t1)**3
So far so good.
The problem occurs when I'm getting the derivative:
>>> p.diff(t)
a1/(-t0 + t1) + a2*(2*t - 2*t0)/(-t0 + t1)**2 + 3*a3*(t - t0)**2/(-t0 + t1)**3
I'm talking about the numerator of the second term:
a2*(2*t - 2*t0)
I would expect that to be:
2*a2*(t - t0)
... and in fact that's how it is done in the third term!
It gets worse when I substitute t1 for t:
>>> p.diff(t).subs(t, t1)
a1/(-t0 + t1) + a2*(-2*t0 + 2*t1)/(-t0 + t1)**2 + 3*a3/(-t0 + t1)
Now the second term contains some parts that should cancel each other
out. The second term should be:
2*a2*/(-t0 + t1)
Again, the third term already has this form.
Is there a way I can tell SymPy to show the terms as I like it?
BTW, I'm using SymPy version 1.1.1.
cheers,
Matthias