Ask Your Question
0

problem while importing a set of integro-differential equations

asked 2012-07-30 12:25:06 +0100

owari gravatar image

updated 2012-07-30 12:27:32 +0100

Hi everyone,

The following code is a minimal code from a longer code for my thesis, made for simplification of error finding procedure.

reset()
forget()
var('x,y,t, x1,y1, x2,y2')
var('x_B1,x_B2, y_B1,y_B2, T')

x_B1=-1; x_B2=1; y_B1=-1; y_B2=1; T=10
assume(x_B1<=x, 0<t)

var('q')           # q is a dummy variable to fill the zeroth place in some lists

R0=[q,x,y,t]
R1=[x1,y1]
R2=[x2,y2]

phi=[q]
for i in range(1,4):
    phi.append([])

    for n in range(3):
        phi[i].append(function('phi_%s_%s' %(i,n), x,y,t,*R1+R2))



# initial estimation

for i in (1,4):
    phi[i][0]=1



# operators

g = lambda i,f: diff(f,R0[i])
It = lambda f: integral(f,t,0,t)
Ixx = lambda f: integral(integral(f,x,x_B1,x),x,x_B1,x)
IntR2 = lambda f:  integral(integral(f,x2,x_B1,x_B2),y2,y_B1,y_B2)




eq=[]


# equations being imported

for n in range(2):
    restore(eq)           # I am not sure if reset() should be used here or restore()?               
    for i in range(1,4):
        eq.append(phi[i][n+1]== It(g(i,phi[i][n])) \
                                 + It(  sum( phi[j][n]*g(j,phi[i][n]) \
                                 + IntR2(phi[j][n](x1=x2,y1=y2)*g(j,phi[i][n])) for j in range(1,4)) ))
        show(eq[i-1])

now it gives back the error that: list index out of range . It seems that the problem is with the part dedicated to the initial estimation as removing that part let us get rid of this error, but I don't understand why the error really stands for ?

Also removing that initial estimation (as this code still doesn't try to solve the set of equations imported, but only save them for later solvation which of course should be embedded in the last loop before the list eq is refreshed) gives back the Maxima's interactive question that is t positive, negative, or zero? This is so while I have already assumed t to be greater than 0!

Any idea?

edit retag flag offensive close merge delete

4 Answers

Sort by » oldest newest most voted
0

answered 2012-08-05 17:54:37 +0100

owari gravatar image

updated 2012-08-05 18:43:45 +0100

Well, thanks God the problem is solved, the error:

'sage.rings.integer.Integer' object is not callable

was something due to the initial estimation being in the form of a constant number, instead of a function, so that calling it by (x=…, …) was nonsense to sage as is a function like 24(x=…, …) ! The question about t being positive or negative is also resolved automatically after the initial estimation was set as a function, like e.g. 0*x+b instead of constant 'b' alone!

Thanks

edit flag offensive delete link more
0

answered 2012-07-31 20:41:24 +0100

owari gravatar image

I also tried the following code:

reset()
forget()

var('x,y,z,t, x1,y1,z1,t1, x2,y2,z2,t2, x3,y3,z3,t3')   # my real variables to be substituted in the function arguments
R0=[x,y,z,t]
R1=[x1,y1,z1,t1]

U_0=[]
U_1=[]

for i in range(4):
    U_0.append(function('U%s0' %i, *R0))
    U_1.append(function('U%s1' %i, *R0+R1))


var('td,xd1,xd2,x_B1')
It = lambda f: integral(f(t=td),td,0,t)     #or use mathematica's algorithm using:  ,algorithm='mathematica_free'
                                            #or use: ,algorithm='sympy' 
Ixx = lambda f: integral(integral(f(x=xd1),xd1,x_B1,xd2),xd2,x_B1,x)

eq=[]
assume(t>0)
for i in range(4):
    #eq.append(It(U_1[i])==It(U_0[i](x=R0[i],y=x+z)*U_1[i])\      # it was working while *U_1[i] had not been included
    #                         +Ixx(U_0[i]))

    #eq.append(It(U_1[i])==integral((U_0[i](x=R0[i],y=x+z)*U_1[i])(t=td),td,0,t)\    #not using "It()" also didn't help
    #                         +Ixx(U_0[i]))

    eq.append(It(U_1[i])==integral(U_0[i](x=R0[i],y=x+z,t=td)*U_1[i](t=td),td,0,t)\
                          +Ixx(U_0[i]))                                              # again here we have problem!

# the problem is with integration code of sage or Maxima it seems. If so maybe I should leave sage to Maple or Mathematica ?

    show(eq[i])

which shows that seemingly the problem is with the integral() function in sage (or Maxima?) rather than the defined integral operators and this destroys all my hopes to use this interesting open source math software, maybe I should leave Sage and use either Maple or mathematica?

edit flag offensive delete link more
0

answered 2012-07-30 13:33:07 +0100

benjaminfjones gravatar image

updated 2012-07-30 15:11:06 +0100

kcrisman gravatar image

The error " list index out of range" means you are trying to index a list beyond its boundary.

In the code:

for i in (1,4):
    phi[i][0]=1

you are iterating over the tuple (1,4), this means i will take the values 1 and 4 in the loop. Perhaps you want to replace (1,4) by range(1,4) like you have in loops above. This will cause i to take the values 1,2,3.

Another comment, probably unrelated to your error, in the definition:

It = lambda f: integral(f,t,0,t)

represents a very common Calculus I student error. You are trying to use t as both the integration variable and the limit of integration. This does not make sense mathematically. If you want the resulting function to be a function of t (the variable that you want to assume is > 0), use a dummy variable in your integration, e.g.

var('s')
It = lambda f: integral(f(s),s,0,t)
edit flag offensive delete link more

Comments

thank you very much, the "list index out of range" error shows why I had always problem with programming, being least careful even though trying my best to be careful. Anyway, I applied your second suggestion by first defining a dummy 'td' variable, then adding a (t=td) variable in the call for the differential and integral operators, like I have done above using (x1=x2,y1=y2) . Now the error is this: 'sage.rings.integer.Integer' object is not callable. Is it something that is related to my definition of operators? Best Regards

owari gravatar imageowari ( 2012-07-30 15:13:30 +0100 )edit

If you post your new code somewhere (e.g. https://gist.github.com/) I'll have a look at it.

benjaminfjones gravatar imagebenjaminfjones ( 2012-07-30 15:57:54 +0100 )edit

here I have copied my present minimal code, only minor changes have been applied into it compared to the above code, taking care of range(1,4) and defining new dummy variables td , … for integration operators and how to call these operators: https://gist.github.com/3210399

owari gravatar imageowari ( 2012-07-30 18:28:02 +0100 )edit
0

answered 2012-07-31 10:43:02 +0100

owari gravatar image

updated 2012-07-31 19:24:59 +0100

Ok, the error was

'sage.rings.integer.Integer' object is not callable

when I was calling the operators using expressions like -- IntR2(phi[j][n](x1=x2,y1=y2)*g(j,phi[i][n])) -- but then I redefined the operators such that themselves include the -- (x1=x2,y1=y2) -- expressions instead of the operator caller! So that now the error became as

ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before integral evaluation *may* help (example of legal syntax is 'assume(t>0)', see `assume?` for more details)
Is  t  positive, negative, or zero?

This is while I still use the dummy variables td, xd1, and xd2, and of course the assume(t>0) statement! Any idea what to do now?

My minimal code now is this:

reset()
forget()
var('x,y,t, x1,y1, x2,y2')
var('x_B1,x_B2, y_B1,y_B2, T')

x_B1=-1; x_B2=1; y_B1=-1; y_B2=1; T=10
assume(x_B1<=x, 0<t)

var('q')                # q is a dummy variable to fill the zeroth place in some lists

R0=[q,x,y,t]
R1=[x1,y1]
R2=[x2,y2]

phi=[q]
for i in range(1,4):
    phi.append([])

    for n in range(3):
        phi[i].append(function('phi_%s_%s' %(i,n), x,y,t,*R1+R2))



# initial estimation

for i in range(1,4):
    phi[i][0]=1



# operators
var('td,xd1,xd2')
g = lambda i,f: diff(f,R0[i])
It = lambda f: integral(f(t=td),td,0,t)
Ixx = lambda f: integral(integral(f(x=xd1),xd1,x_B1,xd2),xd2,x_B1,x)
IntR2 = lambda f:  integral(integral(f(x1=x2,y1=y2),x2,x_B1,x_B2),y2,y_B1,y_B2)



# equations being imported

for n in range(2):
    eq=[]
    for i in range(1,3):
        # FIRST. a minimal full-featured typical equation.
        # RESULT: the error was ('sage.rings.integer.Integer' object is not callable) when I was calling the operators using expressions like -- IntR2(phi[j][n](x1=x2,y1=y2)*g(j,phi[i][n])) -- but now that the operators are redefined to themselves include the -- (x1=x2,y1=y2) -- expressions the error became as (ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before integral evaluation *may* help … Is  t  positive, negative, or zero?)
        eq.append(phi[i][n+1]== It(g(i,phi[i][n])) \
                                + It(  sum( phi[j][n]*g(j,phi[i][n]) \
                                + IntR2(phi[j][n]*g(j,phi[i][n])) for j in range(1,4) ) ))

    show(eq)

What shall I do now?

EDIT.

I have just confused. Right now I tested the following code and it surprisingly worked!

reset()
forget()

var('x,y,z,t, x1,y1,z1,t1, x2,y2,z2,t2, x3,y3,z3,t3') 
R0=[x,y,z,t]
R1=[x1,y1,z1,t1]

U_0=[]
U_1=[]


for i in range(4):
    U_0.append(function('U%s0' %i, *R0))
    U_1.append(function('U%s1' %i, *R0+R1))


var('td,xd1,xd2,x_B1')
It = lambda f: integral ...
(more)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-07-30 12:25:06 +0100

Seen: 559 times

Last updated: Aug 05 '12