Hi,
As a newbie to sage and python I asked a question here around two days ago, and had a chat about it in sage's IRC channel, however, after I learned more from the guys therein and checking different situations by myself I understood my previous question somewhat nonsense, so I am now editing it!
I am working on a multipoint theory of turbulence in fluid mechanics, so I have to solve functions that are simultaneously defined on multi point of space, like f(x,y,z; x1,y1,z1;
), however these functions --which are my main unknowns to be found from a set of many (I mean from some sets of ten to maybe some millions!) coupled nonlinear integro-differential integro-partial differential equations-- sometimes live as integrand to some integrals and sometimes are differentiated and the important thing is that their arguments vary from place to place in an equation and/or in different equations. Maybe I should classify my difficulties into two cases:
how to define many functions automatically and symbolically without specifying their arguments?
how to not specify the arguments to a function and at the same time be able to differentiate it or take its integral?
the answer to the first equation according to what I have read in this website and has been told from the guys in IRC channel is either of the followings:
reset
var('x,y,z,t, x1,y1,z1,t1, x2,y2,z2,t2, x3,y3,z3,t3')
for k in range(10):
function('f%s' %k, nargs=2)
# one can even refuse to determine the number of arguments and let it open by omitting nargs!
or
reset
var('x,y,z,t, x1,y1,z1,t1, x2,y2,z2,t2, x3,y3,z3,t3')
for k in range(10):
s = 'def f%d(*args):\n print args\n' % k
exec(s)
at the end of each of these codes one would have 10 functions f0,f1,
,f9 which can be given their arguments and worked with. For example one can write f2(x,y)+f2(y,z1) which introduce once x and y and another time y and z1 to the same function f2 in one logical line in sage! This is why the second problems seems not to be solvable using the above methods as e.g. f2.diff(x) is nonsense as long as a specific law is not defined for f2, like f(x,y)=2xy^3 ! And it is nonsense to sage as it gives error when one tries to write f2.diff() before defining such a prescribed law for f2, it says function object and NewSymbolicFunction object have no attribute 'diff'
The only way that I can think about is to give my functions a set of dummy variables and replace them with the variables of interest in each equation or differentiation and integration, however, I am not sure it would work as the function is unknown and I don't know if the procedure of many-times changing their variables would affect what is found at the end or not?
And now a second question, I wanted --if possible-- to make my equations for my thesis, but I have been stopped at the very beginning step which is defining the independent and dependent variables! Actually I need to work more readable in sage code --as is on the paper-- by working with vectors R0=(x,y,z,t), R1=(x1,y1,z1,t1),
and vector-fields defined over them as the unknown as my functions to be solved for. So long I have tried the code below:argument, e.g. something like this:
var('x,y,z,t,x1,y1,z1,t1,x2,y2,z2,t2,x3,y3,z3,t3')
reset
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]
R2=[x2,y2,z2,t2]
R3=[x3,y3,z3,t3]
R=[R0,R1,R2,R3] R=[R0,R1,R2,R3]
d f1(R0)/d R0[0] + int int int int f2(R0,R1) f2(R1,R2) dR1 #here in this example f1 has a single spatio-temporal vector as its arguments whereas f2 has two of such spatio-temporal vectors as its arguments # what if I define R as R0+R1+R2+R3, also a list (not list of lists) with all the sublist elements
# no! if so then index of x3 e.g. will become unreasonably weird: R[12] instead of R[3][0]
for k in range(10):
function('f_%s' %k, nargs=2) # I need this way of function definition as it allows the argument not to be specified, as note that dR1 under some integration once the arguments are in the form (R0,R1) and once in the form (R0,R2) and once in the form (R0,R3)
integral means dx1*dy1*dz1*dt1 !
However, this way of defining symbolic function does not allow me to use lists and lists of list as their argument. Searching the web I came across the idea to use an "*" operator before the lists names, but even this way although the code
>> f1 = function("f1", *R[0]) #the operator * turns f(*[a,b,c]) into f(a,b,c)
>> f1
f1(x, y, z, t)
works well as I wish but the code
>> f1 = function("f1", *R) # R is a list of lists
yields into an error that "no canonical coercion from <type 'list'=""> to Symbolic Ring"! Also the codes
f1 = function("f1", *R[0],*R[2])
and
f1 = function("f1", nargs=2)
f1(*R[0],*R[1]);
and
f1 = function("f1", nargs=8)
f1(*R[0],*R[1]); f1(*R[0],*R[2])
yields into invalid syntax errors! This is so while the initial attempt that I made, which was
f1 = function("f1", nargs=2)
f1(R[0],R[1])
was also yielding the obvious error "cannot coerce arguments: no canonical coercion from <type 'list'=""> to Symbolic Ring".
I also redefined the R0,R1,
's as tuple and set types but no result, and also used ** instead of * and again nothing as the result.
I need to integrate w.r.t. the vectors R1,R2,
and also differentiate w.r.t. their elements R[i][j]=Ri[j]. Maybe I should try to work with the variables in the raw form x,y,z,t,x1,y1,
instead of vectors of (x,y,z,t),(x1,y1,z1,t1),
form, but it would be ugly I guess, hope that there is a way to use the vector notations though!
Have you any idea what shall I do at this point?
Regards, owariBest Regards and thanks in advance