Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

using lists in multivariable functions

I wish to create a function that uses elements from a list and is used later on. For example, I have an array M=[m1,m2,...,mn], B=[b1,b2,...,bn] and wish to have a function R(r,u,b)=r+b+u (using the elements from the array B), which I then pass to another function Y(r,u,b,m)=Rbm (using the result from the first function and the values from each array). I tried the map function in python, but it does not seem to play very well with multiple variables, let alone arrays. I plan on using the elements of these arrays in sums later on.

using lists in multivariable functions

I wish to create a function that uses elements from a list and is used later on. For example, I have an array M=[m1,m2,...,mn], B=[b1,b2,...,bn] and wish to have a function R(r,u,b)=r+b+u (using the elements from the array B), which I then pass to another function Y(r,u,b,m)=Rbm (using the result from the first function and the values from each array). In other words, if M=[m1,m2] and B=[b1,b2], I want to be able to have a function R(r,u,b)=[r+b1+u,r+b2+u]and then have that Y(r,u,b,m)=Rbm=[(r+b1+u)b1m1,(r+b2+u)b2m2]. Basically, I wish to do what is mentioned in this post: http://ask.sagemath.org/question/8545/apply-a-function-to-a-list/, but with more than one array. I tried the map function in python, following

sage: m1,m2,b1,b2,u=var('m1','m2','b1','b2','u')

sage: M=[m1,m2], B=[b1,b2]

sage: R(r,b,u)=[r+b+u for b in B]

sage:R(r,b,u)

(r+b1+u,r+b2+u)

This is all what I want. I then want to take R(r,b,u) in another function: Y(r,b,u,m), so that it gets the result I have above. I can't seem to get a way to run through all the possibilities (I could use a loop, but it does not seem to play very well with multiple variables, let alone arrays. I plan on using the elements of these arrays in sums later on.that ends up getting a bit messy as I go deeper in)

using lists in multivariable functions

I wish to create a function that uses elements from a list and is used later on. For example, I have an array M=[m1,m2,...,mn], B=[b1,b2,...,bn] M=[m1,m2,...,mn], B=[b1,b2,...,bn] and wish to have a function R(r,u,b)=r+b+u R(r,u,b)=r+b+u (using the elements from the array B), B), which I then pass to another function Y(r,u,b,m)=Rbm Y(r,u,b,m)=R*b*m (using the result from the first function and the values from each array). In other words, if M=[m1,m2] and B=[b1,b2], M=[m1,m2] and B=[b1,b2], I want to be able to have a function R(r,u,b)=[r+b1+u,r+b2+u]and R(r,u,b)=[r+b1+u,r+b2+u] and then have that Y(r,u,b,m)=Rbm=[(r+b1+u)b1m1,(r+b2+u)b2m2]. Y(r,u,b,m)=R*b*m=[(r+b1+u)*b1*m1,(r+b2+u)*b2*m2]. Basically, I wish to do what is mentioned in this post: http://ask.sagemath.org/question/8545/apply-a-function-to-a-list/, but with more than one array. I tried the following

sage: m1,m2,b1,b2,u=var('m1','m2','b1','b2','u')

sage: M=[m1,m2], B=[b1,b2]

sage: R(r,b,u)=[r+b+u for b in B]

sage:R(r,b,u)

(r+b1+u,r+b2+u)

This is all what I want. I then want to take R(r,b,u) in another function: Y(r,b,u,m), so that it gets the result I have above. I can't seem to get a way to run through all the possibilities (I could use a loop, but that ends up getting a bit messy as I go deeper in)

using lists in multivariable functions

I wish to create a function that uses elements from a list and is used later on. For example, I have an array M=[m1,m2,...,mn], B=[b1,b2,...,bn] and wish to have a function R(r,u,b)=r+b+u (using the elements from the array B), which I then pass to another function Y(r,u,b,m)=R*b*m (using the result from the first function and the values from each array). In other words, if M=[m1,m2] and B=[b1,b2], I want to be able to have a function R(r,u,b)=[r+b1+u,r+b2+u] and then have that Y(r,u,b,m)=R*b*m=[(r+b1+u)*b1*m1,(r+b2+u)*b2*m2]. Basically, I wish to do what is mentioned in this post: http://ask.sagemath.org/question/8545/apply-a-function-to-a-list/, but with more than one array. I tried the following

sage: m1,m2,b1,b2,u=var('m1','m2','b1','b2','u')

sage: M=[m1,m2], B=[b1,b2]

sage: R(r,b,u)=[r+b+u for b in B]

sage:R(r,b,u)

(r+b1+u,r+b2+u)

This is all what I want. I then want to take R(r,b,u) in another function: Y(r,b,u,m), so that it gets the result I have above. I can't seem to get a way to run through all the possibilities (I could use a loop, but that ends up getting a bit messy as I go deeper in)

Edit: The values for mi and bi will eventually have numerical values, but currently they are simply symbolic variables. I am currently using this to simplify some algebraic expressions.