ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 05 Aug 2012 17:54:37 +0200problem while importing a set of integro-differential equationshttps://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/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?Mon, 30 Jul 2012 12:25:06 +0200https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/Answer by owari for <p>Hi everyone,</p>
<p>The following code is a minimal code from a longer code for my thesis, made for simplification of error finding procedure.</p>
<pre><code>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])
</code></pre>
<p>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 ?</p>
<p>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!</p>
<p>Any idea?</p>
https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/?answer=13900#post-id-13900Well, 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!
ThanksSun, 05 Aug 2012 17:54:37 +0200https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/?answer=13900#post-id-13900Answer by owari for <p>Hi everyone,</p>
<p>The following code is a minimal code from a longer code for my thesis, made for simplification of error finding procedure.</p>
<pre><code>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])
</code></pre>
<p>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 ?</p>
<p>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!</p>
<p>Any idea?</p>
https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/?answer=13880#post-id-13880I 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?Tue, 31 Jul 2012 20:41:24 +0200https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/?answer=13880#post-id-13880Answer by benjaminfjones for <p>Hi everyone,</p>
<p>The following code is a minimal code from a longer code for my thesis, made for simplification of error finding procedure.</p>
<pre><code>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])
</code></pre>
<p>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 ?</p>
<p>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!</p>
<p>Any idea?</p>
https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/?answer=13869#post-id-13869The 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)Mon, 30 Jul 2012 13:33:07 +0200https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/?answer=13869#post-id-13869Comment by benjaminfjones for <p>The error " list index out of range" means you are trying to index a list beyond its boundary. </p>
<p>In the code:</p>
<pre><code>for i in (1,4):
phi[i][0]=1
</code></pre>
<p>you are iterating over the tuple <code>(1,4)</code>, this means <code>i</code> will take the values 1 and 4 in the loop. Perhaps you want to replace <code>(1,4)</code> by <code>range(1,4)</code> like you have in loops above. This will cause <code>i</code> to take the values <code>1,2,3</code>.</p>
<p>Another comment, probably unrelated to your error, in the definition:</p>
<pre><code>It = lambda f: integral(f,t,0,t)
</code></pre>
<p>represents a very common Calculus I student error. You are trying to use <code>t</code> 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 <code>t</code> (the variable that you want to assume is > 0), use a dummy variable in your integration, e.g.</p>
<pre><code>var('s')
It = lambda f: integral(f(s),s,0,t)
</code></pre>
https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/?comment=19312#post-id-19312If you post your new code somewhere (e.g. https://gist.github.com/) I'll have a look at it.Mon, 30 Jul 2012 15:57:54 +0200https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/?comment=19312#post-id-19312Comment by owari for <p>The error " list index out of range" means you are trying to index a list beyond its boundary. </p>
<p>In the code:</p>
<pre><code>for i in (1,4):
phi[i][0]=1
</code></pre>
<p>you are iterating over the tuple <code>(1,4)</code>, this means <code>i</code> will take the values 1 and 4 in the loop. Perhaps you want to replace <code>(1,4)</code> by <code>range(1,4)</code> like you have in loops above. This will cause <code>i</code> to take the values <code>1,2,3</code>.</p>
<p>Another comment, probably unrelated to your error, in the definition:</p>
<pre><code>It = lambda f: integral(f,t,0,t)
</code></pre>
<p>represents a very common Calculus I student error. You are trying to use <code>t</code> 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 <code>t</code> (the variable that you want to assume is > 0), use a dummy variable in your integration, e.g.</p>
<pre><code>var('s')
It = lambda f: integral(f(s),s,0,t)
</code></pre>
https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/?comment=19310#post-id-19310here 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/3210399Mon, 30 Jul 2012 18:28:02 +0200https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/?comment=19310#post-id-19310Comment by owari for <p>The error " list index out of range" means you are trying to index a list beyond its boundary. </p>
<p>In the code:</p>
<pre><code>for i in (1,4):
phi[i][0]=1
</code></pre>
<p>you are iterating over the tuple <code>(1,4)</code>, this means <code>i</code> will take the values 1 and 4 in the loop. Perhaps you want to replace <code>(1,4)</code> by <code>range(1,4)</code> like you have in loops above. This will cause <code>i</code> to take the values <code>1,2,3</code>.</p>
<p>Another comment, probably unrelated to your error, in the definition:</p>
<pre><code>It = lambda f: integral(f,t,0,t)
</code></pre>
<p>represents a very common Calculus I student error. You are trying to use <code>t</code> 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 <code>t</code> (the variable that you want to assume is > 0), use a dummy variable in your integration, e.g.</p>
<pre><code>var('s')
It = lambda f: integral(f(s),s,0,t)
</code></pre>
https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/?comment=19313#post-id-19313thank 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 RegardsMon, 30 Jul 2012 15:13:30 +0200https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/?comment=19313#post-id-19313Answer by owari for <p>Hi everyone,</p>
<p>The following code is a minimal code from a longer code for my thesis, made for simplification of error finding procedure.</p>
<pre><code>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])
</code></pre>
<p>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 ?</p>
<p>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!</p>
<p>Any idea?</p>
https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/?answer=13875#post-id-13875Ok, 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(f(t=td),td,0,t)
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))\
+Ixx(U_0[i]))
show(eq[i])
So that I was wrong when I was thinking the error ('sage.rings.integer.Integer' object is not callable) is due to the variable change being called from the argument of the operators instead of being pre-defined inside the operators themselves (which of course was not desired as operator was desired not to be too specific about the variables of the functions to which they apply). Thus, I am totally confused with the errors that I receive from my codes. Please Help
**EDIT2.**
When I multiply "U_0[i](x=R0[i],y=x+z)" in the argument to It operator by a simple function "U_0[i]" it asks: (Is t positive, negative, or zero?) although assume(t>0) is used! Note that again I am calling the operators with the variable changes from the operator call but still no ('sage.rings.integer.Integer' object is not callable)! What are these errors trying to say? Where is the origin to such errors? How can I get rid of them?
Tue, 31 Jul 2012 10:43:02 +0200https://ask.sagemath.org/question/9191/problem-while-importing-a-set-of-integro-differential-equations/?answer=13875#post-id-13875