acer

32333 Reputation

29 Badges

19 years, 321 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

It's quite bad that the ?evalm help-page uses Matrix instead of matrix in Maple 12. Fortunately only the Examples appear affected, and the explanatory text has correctly been left alone.

It makes no sense, since `+`, `.`, ^(-1), etc work directly for Matrices. The Example showing S+2*T demonstrates the mistake, since S+2*T will get computed elementwise even without being wrapped in an evalm call.

And evalm applied to a Matrix is unnecessary (Matrices don't have last_name_eval), and doing so inefficiently produces an unnecessary copy and increases the amount of garbage to be collected.

Also, since Matrices and Vectors don't have last_name_eval, the evalm environment isn't any means to do symbolic addition or subtraction on just the names of those objects. Again, the Example on that help-page for S+2*T makes that point, since for S and T as Matrices then S+2*T can't be entered unwrapped without the elementwise computation occuring. (See here, for a rough and ready attempt at such.)

This may have been a misguided and overzealous part of a sweep to deprecate linalg and matrix. It would have been much better to simply have noted the "deprecated" aspect as a brief note at the start of the ?evalm help-page.

acer

Yes, that's right; that code I first posted replaced `*` with `&*` for any calls to `*` which had only objects of type `array` as its operands. And matrix and vector objects are both of type `array`, hence the replacement works for matrix*matrix and matrix*vector.

Here's how one might go about it, using 2-argument eval to substitute into plain names. I'm using Matrix objects, which are more modern and work with LinearAlgebra as I feel sure you have realized.

> meqs := {
>   TAM = Matrix(3,3,[[Xud,0,0],[0,Yvd,0],[0,0,Zwd]]),
>   TRAM = Matrix(3,3,[[0,Xqd,0],[Ypd,0,Yrd],[0,Zqd,0]]),
>   RAM = Matrix(3,3,[[Kpd,0,Krd],[0,Mqd,0],[Npd,0,Nrd]]),
>   RTAM = Matrix(3,3,[[0,Kvd,0],[Mud,0,Mwd],[0,Nvd,0]])
>         }:
>
> veqs := {
>   Vel = Vector(3,[u,v,w]),
>   Omg = Vector(3,[p,q,r])
>         }:
>
> MAM := Matrix(2,2,[['TAM','TRAM'],['RTAM','RAM']]);
                                    [TAM     TRAM]
                             MAM := [            ]
                                    [RTAM    RAM ]
                                                                                
> S := Vector(2,['Vel','Omg']);
                                        [Vel]
                                   S := [   ]
                                        [Omg]
 
>
> EoM := MAM . S;
                                 [TAM Vel + TRAM Omg]
                          EoM := [                  ]
                                 [RTAM Vel + RAM Omg]
 
>
> EoM1 := Matrix(convert(eval(MAM, meqs),listlist)) . Vector(convert(eval(S, veqs),list));
                                [    Xud u + Xqd q    ]
                                [                     ]
                                [Yvd v + Ypd p + Yrd r]
                                [                     ]
                                [    Zwd w + Zqd q    ]
                        EoM1 := [                     ]
                                [Kvd v + Kpd p + Krd r]
                                [                     ]
                                [Mud u + Mwd w + Mqd q]
                                [                     ]
                                [Nvd v + Npd p + Nrd r]

There is only a limited amount of "abstract linear algebra" available via the evalm operator. I'm quite hesitant to try to extend it, since matrix/vector objects have become rather outdated. The only "advantage" they might still have rests in the functionality provided by evalm, but since that is quite incomplete and limited it doesn't seem best to enhance it.

 

BTW, matrix/vector objects have last_name_eval (see the help-page on that topic). This allows them to be used as names on the surface, even while they are assigned as arrays. This aspect is what allows the degree of abstract manipulation of them, without having all elementwise operations occur.

I can't help but take a crude stab at some abstract manipulation of names, with a Matrix/Vector approach. Below, I attach actual Matrices and Vectors to names as attributes. For a long time, I've considered investigating the feasibility of this approach. This is not a thorough or especially careful attempt, but it might serve for you.

> restart:
>
> setattribute(TAM,object=Matrix(3,3,[[Xud,0,0],[0,Yvd,0],[0,0,Zwd]])):
> setattribute(TRAM,object=Matrix(3,3,[[0,Xqd,0],[Ypd,0,Yrd],[0,Zqd,0]])):
> setattribute(RAM,object=Matrix(3,3,[[Kpd,0,Krd],[0,Mqd,0],[Npd,0,Nrd]])):
> setattribute(RTAM,object=Matrix(3,3,[[0,Kvd,0],[Mud,0,Mwd],[0,Nvd,0]])):
> setattribute(Vel,object=Vector(3,[u,v,w])):
> setattribute(Omg,object=Vector(3,[p,q,r])):
>
> EvalM := proc(x)
>   if type(x,`+`) then
>      `+`(op(map('procname',[op(x)])));
>   elif type(x,`*`) then
>      `.`(op(map('procname',[op(x)])));
>   elif type(x,specfunc(anything,`&*`)) then
>     `.`(op(map('procname',[op(x)])));
>   elif type(x,Matrix) then
>     Matrix(map(t->map(EvalM,t),convert(x,listlist)));
>   elif type(x,Vector) then
>     Vector(map('procname',convert(x,list)));
>   elif type(attributes(x),identical(object)={Matrix,Vector}) then
>     rhs(attributes(x));
>   else
>      x;
>   end if;
> end proc:
>
> EvalM(TAM);
                              [Xud     0      0 ]
                              [                 ]
                              [ 0     Yvd     0 ]
                              [                 ]
                              [ 0      0     Zwd]
 
> EvalM(Vel);
                                      [u]
                                      [ ]
                                      [v]
                                      [ ]
                                      [w]
 
>
> MAM := Matrix(2,2,[[TAM,TRAM],[RTAM,RAM]]);
                                    [TAM     TRAM]
                             MAM := [            ]
                                    [RTAM    RAM ]
 
> S := Vector(2,[Vel,Omg]);
                                        [Vel]
                                   S := [   ]
                                        [Omg]
 
>
> EvalM(MAM);
                    [Xud     0      0      0     Xqd     0 ]
                    [                                      ]
                    [ 0     Yvd     0     Ypd     0     Yrd]
                    [                                      ]
                    [ 0      0     Zwd     0     Zqd     0 ]
                    [                                      ]
                    [ 0     Kvd     0     Kpd     0     Krd]
                    [                                      ]
                    [Mud     0     Mwd     0     Mqd     0 ]
                    [                                      ]
                    [ 0     Nvd     0     Npd     0     Nrd]
 
>
> EvalM(MAM &* S);
                            [    Xud u + Xqd q    ]
                            [                     ]
                            [Yvd v + Ypd p + Yrd r]
                            [                     ]
                            [    Zwd w + Zqd q    ]
                            [                     ]
                            [Kvd v + Kpd p + Krd r]
                            [                     ]
                            [Mud u + Mwd w + Mqd q]
                            [                     ]
                            [Nvd v + Npd p + Nrd r]
 
>
> MAM . S;
                              [TAM Vel + TRAM Omg]
                              [                  ]
                              [RTAM Vel + RAM Omg]
 
>
> EvalM(MAM . S);
                            [    Xud u + Xqd q    ]
                            [                     ]
                            [Yvd v + Ypd p + Yrd r]
                            [                     ]
                            [    Zwd w + Zqd q    ]
                            [                     ]
                            [Kvd v + Kpd p + Krd r]
                            [                     ]
                            [Mud u + Mwd w + Mqd q]
                            [                     ]
                            [Nvd v + Npd p + Nrd r]

I'd be quite interested in what the experts say. Is this scheme obviously going to be lacking for more involved problems? I'm referring to the idea of using attributes, and not to the particular (crude) EvalM routine above. (Also, a more user-friendly constructor could be written, instead of setattribute.) Would not some sorts of module object serve much better?

I realize that "abstract linear algebra" is a wide concept (and probably means different functionality to different people). Should we just wait for such a package to appear, or might we discuss, design, and implement it in pieces ourselves?

acer

I hope that someone wil take the time to post something prettier than this,

> map(T->evalm(subsindets(T,'`*`'(array),t->`&*`(op(t)))),EoM1);
                           [[    Xud u + Xqd q    ]]
                           [[                     ]]
                           [[Yvd v + Ypd p + Yrd r]]
                           [[                     ]]
                           [[    Zwd w + Zqd q    ]]
                           [                       ]
                           [[Kvd v + Kpd p + Krd r]]
                           [[                     ]]
                           [[Mud u + Mwd w + Mqd q]]
                           [[                     ]]
                           [[Nvd v + Npd p + Nrd r]]

> map(T->subsindets(T,'`*`'(array),t->`&*`(op(t))),EoM1);
                        [(TAM &* Vel) + (TRAM &* Omg)]
                        [                            ]
                        [(RTAM &* Vel) + (RAM &* Omg)]

> map(evalm,%);
                           [[    Xud u + Xqd q    ]]
                           [[                     ]]
                           [[Yvd v + Ypd p + Yrd r]]
                           [[                     ]]
                           [[    Zwd w + Zqd q    ]]
                           [                       ]
                           [[Kvd v + Kpd p + Krd r]]
                           [[                     ]]
                           [[Mud u + Mwd w + Mqd q]]
                           [[                     ]]
                           [[Nvd v + Npd p + Nrd r]]

That final object is a 2x1 array, with each entry being a 3x1 array. Did you also want it "flattened"?

You might also be able to approach the whole problem from the other direction, by creating Matrices/matrices with only names as entries for the blocks, and then substituting/evaluating those names with Matrix/matrix values. But then it'd be messier to "play around" with the block matrices if you ever wanted to have blocks of blocks, etc.

This sort of thing is one type of functionality that I'd like to see in a new abstract linear algebra package that worked with Matrices (and LinearAlgebra).

note: the type checked in the subsindets call should work for matrix-matrix and matrix-vector multiplication, since both are of type `array`.

acer

Does ExcelTools:-Export() respect the setting of currentdir()?

acer

Does ExcelTools:-Export() respect the setting of currentdir()?

acer

The change to the Application Center, to allow downloads without logging in, is excellent.

acer

The site is quite slow. Is it expected to serve faster sometime soon?

Is the login of Mapleprimes tied in to that of the new Application Centre? Could it be made like that, so that if logged into Mapleprimes then one's browser session also had access to Applications (for comments, etc). Or is a separate "Maplesoft .com account" absolutely necessary?

Oh, whoops, it just gave me an HTTP Error 500 (Internal Server Error). But now it's OK again. Transient glitch only.

thanks,
acer

> restart:
> whattype(B);
                                   symbol

> plots:-matrixplot(B);
Error, (in plots/matrixplot) invalid input: `convert/Matrix` expects
its 1st argument, M, to be of type {Array, Matrix, Vector, array, list},
but received B

> B:=Matrix([[1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7]]):
> whattype(B);
                                   Matrix
> plots:-matrixplot(B,axes=boxed); # it works

> B:=matrix(4,4,[1,2,3,4,2,3,4,5,3,4,5,6,4,5,6,7]):
> whattype(B);
                                   symbol
> plots:-matrixplot(B,axes=boxed); # it works

Note that if B had been assigned a lowercase-m matrix, then whattype(B) would still return symbol. But in that case, the plot should work. It's not entirely clear whether you've simply forgotten to assign anything to B or not.

acer

> restart:
> whattype(B);
                                   symbol

> plots:-matrixplot(B);
Error, (in plots/matrixplot) invalid input: `convert/Matrix` expects
its 1st argument, M, to be of type {Array, Matrix, Vector, array, list},
but received B

> B:=Matrix([[1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7]]):
> whattype(B);
                                   Matrix
> plots:-matrixplot(B,axes=boxed); # it works

> B:=matrix(4,4,[1,2,3,4,2,3,4,5,3,4,5,6,4,5,6,7]):
> whattype(B);
                                   symbol
> plots:-matrixplot(B,axes=boxed); # it works

Note that if B had been assigned a lowercase-m matrix, then whattype(B) would still return symbol. But in that case, the plot should work. It's not entirely clear whether you've simply forgotten to assign anything to B or not.

acer

Could it be that B hasn't actually been assigned a matrix or Matrix?

acer

Could it be that B hasn't actually been assigned a matrix or Matrix?

acer

If you are using Maple 12, then the command Explore(%) in the code above should pop-up a box. It's a tool to explore expressions or plots with parameters in them.

acer

If you are using Maple 12, then the command Explore(%) in the code above should pop-up a box. It's a tool to explore expressions or plots with parameters in them.

acer

Here's a possible way to visualize it.

with( LinearAlgebra ):
A := <<1|1>,<4|1>>;
B := MatrixExponential(A,t);
C := Vector(2,[c1,c2]);
M := B.C;

It seems that you want a parameterized plot, with x being M[1] and y being M[2]. So you could try something like this.

When the Explore set-up window pops up, change the lower and upper values for both c1 and c2 to -3.0 and 3.0 say. Check the boxes to skip t and view.

'plot'([M[1], M[2],t=-10..10],view=[-10..10,-10..10]):
Explore(%);

You could also make that 'plot' call with t=a..b, to get sliders which controlled the length. Set the slider range for a from -2.0 to 0.0 and for b from 0.0 to 2.0 say.

acer

Here's a possible way to visualize it.

with( LinearAlgebra ):
A := <<1|1>,<4|1>>;
B := MatrixExponential(A,t);
C := Vector(2,[c1,c2]);
M := B.C;

It seems that you want a parameterized plot, with x being M[1] and y being M[2]. So you could try something like this.

When the Explore set-up window pops up, change the lower and upper values for both c1 and c2 to -3.0 and 3.0 say. Check the boxes to skip t and view.

'plot'([M[1], M[2],t=-10..10],view=[-10..10,-10..10]):
Explore(%);

You could also make that 'plot' call with t=a..b, to get sliders which controlled the length. Set the slider range for a from -2.0 to 0.0 and for b from 0.0 to 2.0 say.

acer

First 499 500 501 502 503 504 505 Last Page 501 of 591