I think one of your problems was that the definition of L2 was
illegal since it ran into an out of range index problem. (In Python,
all lists start at 0.)

There may be better ways but, in any case, the following works.
Note I had to change the definition of L2 so that you would not get an error:

sage: a = [-1, 0, 15/10, 32/10, 5]
sage: k = len(a)
sage: P.<t> = PolynomialRing(QQ, "t")
sage: delta = lambda x,y: int(x==y)
sage: w = lambda j,k: (t-a[j-1])/(a[j+k-2]-a[j-1])
sage: W1 = lambda r,s: piecewise([[(a[i-1],a[i]),w(r,s)] for i in range(1,k)])
sage: W2 = lambda r,s: piecewise([[(a[i-1],a[i]),1-w(r,s)] for i in range(1,k)])
sage: L1 = []
sage: for j in range(1,k):
    L1.append( piecewise([[(a[i-1],a[i]),delta(i,j)*t^0] for i in range(1,k)]) )
....:
sage: L2 = []
sage: for j in range(1,k-1):
    L2.append( W1(j,2)*L1[j-1]+(W2(j+1,2))*L1[j] )
....:

This may not be what you wanted, but of you can modify the code to
give you what you want.

On Fri, Jun 26, 2009 at 3:50 AM, David Sevilla<[email protected]> wrote:
>
> Hi,
>
> On Jun 25, 9:12 pm, David Joyner <[email protected]> wrote:
>> I know multiplication is very finicky. You might try using
>> R.<t> = PolynomialRing(RR, "t") instead, but I'm not sure that will work 
>> either.
>>
>> Can you post more of your code so I can give a more detailed answer?
>
> a = [-1, 0, 1.5, 3.2, 5]
> k = len(a)
> t = var('t')
>
> def delta(c,d):
>    if c == d:
>        return 1
>    else:
>        return 0
>
> def w(j,k,t):
>    return (t-a[j-1])/(a[j+k-2]-a[j-1])
> # for j,k integers it is just an expression in t
>
> L1 = []
> for j in [1..k-1]:
>    L1.append( piecewise([[(a[i-1],a[i]),delta(i,j)] for i in
> [1..k-1]]) )
>
> L2 = []
> for j in [1..k-2]:
>    L2.append( w(j,2,t)*L1[j]+(1-w(j+1,2,t))*L1[j+1] )
>
> Traceback (click to the left for traceback)
> ...
> TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and
> '<type 'instance'>'
>
> w(1,2,t)*L1[1]
> Traceback (click to the left for traceback)
> ...
> TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and
> '<type 'instance'>'
>
> L1[1]; type(L1[1])
> Piecewise defined function with 4 parts, [[(-1, 0), 0], [(0,
> 1.50000000000000), 1], [(1.50000000000000, 3.20000000000000), 0],
> [(3.20000000000000, 5), 0]]
> <type 'instance'>
>
> w(1,2,t); type(w(1,2,t))
> t + 1
> <type 'sage.symbolic.expression.Expression'>
>
> I am guessing that having them both as functions of a variable "t" I
> should be able to manipulate them (it seems piecewise is not a
> function). Assuming, that is, that things like the "1" in the
> definition of L2 above would be coerced accordingly.
>
> David
>
>> On Thu, Jun 25, 2009 at 2:17 PM, David Sevilla<[email protected]> wrote:
>>
>> > Hi,
>>
>> > I am trying to construct the usual spline basis functions. In short, I
>> > start with several piecewise functions that take values 1 and 0 only,
>> > and then make combinations of them. But there is something with the
>> > syntax that I am not managing to do well, I suppose:
>>
>> > L[1]
>> > Piecewise defined function with 3 parts, [[(-1, 0), 0], [(0,
>> > 1.50000000000000), 0], [(1.50000000000000, 3.20000000000000), 1]]
>>
>> > t = var('t')
>> > L[1]*t
>> > Traceback (click to the left for traceback)
>> > ...
>> > AttributeError: 'sage.symbolic.expression.Expression' object has no
>> > attribute 'domain'
>>
>> > It seems to me that I have to set things up so that L[1] is a function
>> > of t as well. I tried "lambda t: " in front where I define it, but now
>> > L[1] is a function whose value is always a certain piecewise
>> > function  :)
>>
>> > Any suggestions?
>>
>> > Thanks,
>>
>> > David
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to