I'm trying to compute the lagrange polynomial in 't' through three
points containing 'x' terms.
1. It's hell =) but there's sort-of a trac ticket for that already[1].
The example given doesn't work when the data contain other symbolic
values. I ultimately had to get the coefficients and reconstruct the
polynomial from them.
2. Along the way, I hit something more confusing. The following prints
out two different polynomials:
from sage.all import *
x,t = var('x,t')
points = [ (QQ(0.5)*sqrt(2), QQ(0.25)*(2*x - sqrt(2))**2),
(0, 0),
(-QQ(0.5)*sqrt(2), 0) ]
# Use anything other than 'x' or 't'...
R = SR['u']
p1 = R.lagrange_polynomial(points)
print "p1:",p1
p2 = p1.subs(u=t)
print "p2:",p2
Another oddity is that,they compare equal in a prompt, even though one
has no t^2 term:
> x,t = var('x,t')
> p1 = (1/4*(2*x - sqrt(2))^2)*t^2 + (1/8*(2*x - sqrt(2))^2*sqrt(2))*t
> p2 = 1/8*(2*(2*x - sqrt(2))^2*t + (2*x - sqrt(2))^2*sqrt(2))*t
> (p1 - p2).full_simplify()
0
> p1.coefficient(t, 2)
1/4*(2*x - sqrt(2))^2
> p2.coefficient(t, 2)
0
Where have I gone awry?
[1] http://trac.sagemath.org/sage_trac/ticket/9794
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org