Hi, with numbers the problem is like 
this<https://ece.uwaterloo.ca/~dwharder/NumericalAnalysis/05Interpolation/multi/>I
 assume:

  data=zip([randint(-4, 5) for i in range(ns)],[randint(-1, 16) for i in 
range(ns)])
  A_data=matrix(ns,ns,[map(int,A(x=s,y=t).list()) for s,t in data])
  tofit=[randint(-7, 7) for i in range(ns)]

  print tofit
  if A_data.det()!=0: print A_data*vector(A_data.inverse()*vector(tofit))

[-4, -6, -6, -6, -4, 5, 7, -2, -7, 6]
(-4, -6, -6, -6, -4, 5, 7, -2, -7, 6)

Here map(int,A(x=s,y=t).list()) converts a symbolic expression A(x=s,y=t) 
to ints. If you leave out map, and just use A(x=s,y=t).list(), Sage will 
keep running as the inverse of a symbolic expression is solvable (for 
instance via Cramer's rule <http://en.wikipedia.org/wiki/Cramer's_rule>) 
but very complex.
If you want a symbolic expression (because the data points (x,y) have 
special properties) I would use a subroutine to apply Cramer's 
rule<http://math1.skku.ac.kr/home/pub/86/>. 
The reason is that Sage is fast in determining the 
determinant<http://en.wikipedia.org/wiki/Determinant>: 
A_data.det(). 

Roland

Op vrijdag 10 mei 2013 19:00:25 UTC+2 schreef Matt het volgende:
>
> I'm new to Sage, coming from a Maple background. I have some fairly 
> complicated multivariate polynomial Vandermonde inverses to generate, and 
> my method of choice is constructing a generic polynomial, applying whatever 
> operations I wish (differentiate, integrate, sample, etc) for constraints, 
> then taking the Jacobian of the constraints with respect to polynomial 
> coefficients (which are symbolic placeholders at this point), and finally 
> inverting that Jacobian and multiplying by the RHS data that fits those 
> constraints. This requires the use of a symbolic vector as a placeholder. 
> The only way I've found of doing this so far (for a half-tensor 2-D 
> polynomial) is:
>
> N = 4
> var('x','y')
> ns = (N+1)*N/2
> p = 0
> count = 0
> for j in range(N) :
>     for i in range(N) :
>         if ( i + j ) < N :
>             p = p + var('a%s'%count) * x^i * y^j
>             count = count + 1
>
> And this works just fine, and I can take the Jacobian of constraints as:
>
> A = jacobian( constr , ( [ var('a%s'%i) for i in range(ns) ] ) )
>
> But, I cannot then assign to the coefficients to retrieve the fitted 
> polynomial and perform further operations on it. I've tried this, and it 
> fails:
>
> coefs = A^-1 * vector( [ var('m%s'%i) for i in range(ns) ] )
> for i in range(ns) :
>     'a%s'%i = coefs[i]
>
> As I expected, I get "SyntaxError: can't assign to operator." How can I 
> assign to a generated variable name? Better still, is there a way to create 
> a symbolic vector that isn't assigned values, that I can use as a 
> placeholder? Thanks,
>
> -Matt
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to