On Sun, Nov 18, 2012 at 10:03 PM, Chris Smith <smi...@gmail.com> wrote:
>> Hey very nice, but I actually want to later on substitute values for
>> lamb0..3, and if lamb is an undefined function as the above, how do I
>> do that?
>>
>
>>>> f=Function('f')
>>>> f(1)+f(2)
> f(1) + f(2)
>>>> _.replace(f, lambda x: x**2)

Hi a further thought on this previous reply of Chris':

I am sure all will agree that subscripted variables are often used in
mathematics. Hence my need for lamb(da)0...3 (...n). However, we are
unable to use a Python list for this although it can be easily
constructed using list(symbols('lamb:4')), because I can't include it
as part of a symbolic expression since anything like lamb[i] will
throw an index error. Chris' suggestion above is to use a function
lamb instead, and to replace it at the end using replace.

But if I want to create a series of simultaneous equations involving a
series of subscripted variables and give them to solve, the above
method doesn't work:

In [1]: from sympy import symbols,Function,solve
In [2]: x,y=symbols('x,y')
In [3]: A=Function('A')
In [4]: solve([x + 5*y - 2, -3*x + 6*y - 15])
Out[4]: {x: -3, y: 1}
In [5]: solve([A(0) + 5*A(1) - 2, -3*A(0) + 6*A(1) - 15])
Out[5]: []

whereas what I would expect with subscripted variables would be to get:
{A(0): -3, A(1): 1 }

What is the way out here? Or in other words, what is the SymPy way to
use subscripted variables? That is, I want x0 x1 etc and need to be
able to specify them by x and 0,1 etc. Of course, symbols('x'+str(i))
would work but it is a hack, and it wouldn't make it convenient to
construct expressions using such subscripted variables...

Thanks!

-- 
Shriramana Sharma

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to