how do I get rk to do anything?



On Thu, 25 Jan 2007, Dan Solomon wrote:

> It is often convenient to express a linear vector ODE in matrix form,
> dxdt = A.x, which works if A is a square matrix and x & dxdt are
> column vectors.  But you know that.  Are you pointing out that the
> tools in Maxima can deal with things either way?  That rk(dxdt, x,
> init, [t,0,1,.1]) will work as long as dxdt, x, and init are all
> column vectors or all row vectors?

No, rk needs "horizontal" lists as in the examples.

If you write something which involves column vectors, you simply use
the "transpose" operator to convert them into row vectors to use in rk.

Is this clear?

Consider the following.

(%i37) A: matrix([2,1],[1,1]);
                                    [ 2  1 ]
(%o37)                             [      ]
                                    [ 1  1 ]
(%i38) xb: [x,y];
(%o38)                              [x, y]
(%i39) dxdt: A. transpose(xb);
                                   [ y + 2 x ]
(%o39)                            [         ]
                                   [  y + x  ]
(%i40) transpose(dxdt);
(%o40)                        [ y + 2 x  y + x ]
(%i41) /* note that it is not of the proper form, so try */
                                    transpose(dxdt)[1];
(%o41)                         [y + 2 x, y + x]
(%i42) init: [2.0,1.2];
(%o42)                            [2.0, 1.2]

(%i43) t_range: [t,0,1,.1];
(%o43)                          [t, 0, 1, 0.1]
(%i44) eq: transpose(dxdt)[1];
(%o44)                         [y + 2 x, y + x]
(%i45) sol: rk(eq, [x,y], init, t_range);
(%o45) [[0, 2.0, 1.2], [0.1, 2.594321666666667, 1.565906666666667],
[0.2, 3.366336759902778, 2.041579232534722],
[0.3, 4.369215513802731, 2.659876580550931],
[0.4, 5.67203965829093, 3.463491356006614],
[0.5, 7.364564089526698, 4.507892837463743],
[0.6, 9.563403519158422, 5.865150492917444],
[0.7, 12.42007054210332, 7.628901775404184],
[0.8, 16.13141917902195, 9.920806583594768],
[0.9, 20.95321375670773, 12.89893328730419],
[1.0, 27.21775841614106, 16.76865435876751]]
(%i46)

-sen

> On Jan 25, 2007, at 4:29 PM, sen1 at math.msu.edu wrote:
>
>> What's the difference between using rows or columns?
>>
>> (%i5) x: [u,v,w];
>> (%o5)                              [u, v, w]
>> (%i6) transpose(x);
>>                                      [ u ]
>>                                      [   ]
>> (%o6)                                [ v ]
>>                                      [   ]
>>                                      [ w ]
>>
>> -sen
>>
>>
>> ----------------------------------------------------------------------
>> -----
>>  | Sheldon E. Newhouse            |    e-mail:
>> sen1 at math.msu.edu           |
>>  | Mathematics Department         |       				   |
>>  | Michigan State University      | telephone:
>> 517-355-9684                |
>>  | E. Lansing, MI 48824-1027 USA  |       FAX:
>> 517-432-1562                |
>>
>> ----------------------------------------------------------------------
>> -----
>>
>> On Thu, 25 Jan 2007, Dan Solomon wrote:
>>
>>> that would make row vectors, instead of column vectors, right?  Which
>>> should be OK for using rk, but perhaps not for other purposes, is why
>>> I was doing matrix([x1], [x2], [x3]) - i understood the documentation
>>> to mean matrix () needs its rows inside separate [ ].  I was trying
>>> to make a 3 row by 1 column matrix, i.e., a column 3 vector.
>>>
>>> But anyway, don't you have to say x:matrix([x1,x2,x3]); rather than
>>> just x:[x1,x2,x3]; ?
>>>
>>>
>>> On Jan 25, 2007, at 3:35 PM, sen1 at math.msu.edu wrote:
>>>
>>>>
>>>> On Thu, 25 Jan 2007, Dan Solomon wrote:
>>>>
>>>>> I really appreciate everyone's help, but I have two questions.
>>>>> 1.  How can I learn the differences/relationships between lists,
>>>>> arrays, and matrices?  I've read the documentation (a few
>>>>> times), and
>>>>> I never picked up the idea that if I define init[1], init[2], and
>>>>> init
>>>>> [3], maxima wouldn't realize that "init" meant the 3 vector.
>>>>>
>>>>> 2.  is there a way to define my vectors, dxdt, x, and init, so that
>>>>> it will work to issue the command
>>>>> rk(dxdt, x, init, [t,0,1,.1])
>>>>
>>>>
>>>> How about e.g.,
>>>>
>>>> x: [x1,x2,x3];
>>>>
>>>> dxdt: [x1*exp(-x2) - x2^(-3), x1 + x2, x1 + x3];
>>>>
>>>> init: [2.0, -1.1, 3.2];
>>>>
>>>> sol: rk(dxdt, x, init, [t,0,1,.1]);
>>>>
>>>>
>>>>> Thanks again!
>>>>> Dan
>>>>> On Jan 25, 2007, at 10:46 AM, sen1 at math.msu.edu wrote:
>>>>>
>>>>>> My guess is that Dan wanted to write his system of DE's using
>>>>>> matrix
>>>>>> methods to simply express them.  So, his original right hand side
>>>>>> is a
>>>>>> vector function whose components are 1x1
>>>>>> matrices of functions instead of functions.  So, all that was
>>>>>> necessary to get it to work is to replace
>>>>>>
>>>>>> [dxdtau[1],dxdtau[2],dxdtau[3]]
>>>>>>
>>>>>> by
>>>>>>
>>>>>> [dxdtau[1][1],dxdtau[2][1],dxdtau[3][1]]
>>>>>>
>>>>>> Thus, instead of his right side of the DE looking like (using
>>>>>> x,y,z
>>>>>> instead of x[1],x[2],x[3] for easier writing)
>>>>>>
>>>>>> [[x^2 + y^2], [x - y], [z*y*z]], it should have looked like
>>>>>>
>>>>>> [x^2 + y^2, x - y, z*y*z]
>>>>>>
>>>>>> Hence, the simple fix above.  I think Jaime's manual and the
>>>>>> examples
>>>>>> are fine as written.  If one wants to use matrices of functions to
>>>>>> define systems of equations, one just has to convert back to the
>>>>>> standard thing maxima expects.  I don't know if it is worth
>>>>>> rewriting
>>>>>> the code to take care of this.  But, it might be worthwhile to
>>>>>> put an
>>>>>> example or two in the manual to show how to deal with this.
>>>>>>
>>>>>> -sen
>>>>>>
>>>>>>
>>>>>> ------------------------------------------------------------------
>>>>>> --
>>>>>> --
>>>>>> -----
>>>>>>   | Sheldon E. Newhouse            |    e-mail:
>>>>>> sen1 at math.msu.edu           |
>>>>>>   | Mathematics Department         |       				   |
>>>>>>   | Michigan State University      | telephone:
>>>>>> 517-355-9684                |
>>>>>>   | E. Lansing, MI 48824-1027 USA  |       FAX:
>>>>>> 517-432-1562                |
>>>>>>
>>>>>> ------------------------------------------------------------------
>>>>>> --
>>>>>> --
>>>>>> -----
>>>>>>
>>>>>> On Thu, 25 Jan 2007, Robert Dodier wrote:
>>>>>>
>>>>>>> Dan, it looks like the basic problem is that Maxima treats lists
>>>>>>> and
>>>>>>> matrices in ways that are somewhat less than obvious.
>>>>>>> I'll try to clarify some points.
>>>>>>>
>>>>>>> On 1/25/07, Jaime E. Villate <villate at fe.up.pt> wrote:
>>>>>>>> On Thu, 2007-01-25 at 06:12 -0500, Dan Solomon wrote:
>>>>>>>>> I don't understand your comment.  Don't I have x as a 3-vector?
>>>>>>>>
>>>>>>>> No, you don't. x[1], x[2], x[3] have no relation to the
>>>>>>>> variable x.
>>>>>>>> x and x[1] are considered different variables in Maxima.
>>>>>>>
>>>>>>> Well, if the user writes x:[a, b, c] (i.e. assign a list to x)
>>>>>>> then
>>>>>>> x[1], x[2], and x[3] are indeed related to x; those are the three
>>>>>>> elements of x.
>>>>>>>
>>>>>>> Dan, I think you want x:[a, b, c], not x[1]:a, etc -- in the
>>>>>>> latter
>>>>>>> form, x doesn't refer collectively to a, b, and c.
>>>>>>> Whether that's a design flaw is a topic for a rainy day ....
>>>>>>>
>>>>>>>> The first argument given to rk must be a list of expressions.
>>>>>>>> You
>>>>>>>> first
>>>>>>>> tried with a 3x1 matrix dxdtau. It won't work. You then tried
>>>>>>>>   [dxdtau[1],dxdtau[2],dxdtau[3]]
>>>>>>>>
>>>>>>>> this is not a list of expressions either. Please notice that
>>>>>>>> since
>>>>>>>> dxdtau is a matrix, dxdtau[1] is the first row of that matrix;
>>>>>>>> namely,
>>>>>>>> it is a list itself.
>>>>>>>
>>>>>>> Lists are not row or column matrices, and the elements of a
>>>>>>> row or column matrix must be indexed by 2 indices (one of which
>>>>>>> is always 1). Dan, probably what you want is to make dxdtau a
>>>>>>> list.
>>>>>>>
>>>>>>> Hope this helps -- I'm sorry if the treatment of lists and
>>>>>>> matrices
>>>>>>> is confusing. I would be interested to hear your comments on this
>>>>>>> point.
>>>>>>>
>>>>>>> Robert Dodier
>>>>>>> _______________________________________________
>>>>>>> Maxima mailing list
>>>>>>> Maxima at math.utexas.edu
>>>>>>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>>>>>>
>>>>>> _______________________________________________
>>>>>> Maxima mailing list
>>>>>> Maxima at math.utexas.edu
>>>>>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>>>> _______________________________________________
>>>>> Maxima mailing list
>>>>> Maxima at math.utexas.edu
>>>>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>>>>
>>>> _______________________________________________
>>>> Maxima mailing list
>>>> Maxima at math.utexas.edu
>>>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>> _______________________________________________
>>> Maxima mailing list
>>> Maxima at math.utexas.edu
>>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>