Functions as matrix elements???? I want to see the algebraic expressions behind the matrix elements, but also do calculations

Hi,

I am an absolute beginner with Maple and am appreciating any help.

Basically, I want to use maple because it can deal with algebraic expressions. For example with Matrixmultiplication I don't just want to see the final result, but also I want to see the algebra behind each matrix element. 

So I have defined the following 2 matrices :

rot_x := matrix([[1,0,0], [0, cos(alpha), -sin(alpha)], [sin(alpha), cos(alpha), 0]]); 

rot_y := matrix([[cos(alpha), 0, sin(alpha)],[0,1,0],[-sin(alpha), 0, cos(alpha)]]);

When I now multiply Rot_x with Rot_Y, Maple gives me a nice output of the algebraic expression behind each matrix element...which is great...

Result :=multiply(Rot_x, Rot_y);   ====> shows a lot of cos(alpha)* sin(alpha) etc....

...But now, I would like to assign a value to the variable alpha (e.g. 90degrees), so that the matrices rot_x, rot_y and result appear just with the numbers in it, instead of algebraic expressions......

It would be great if somebody gave me a quick kickstart......

THANKS for any contribution.....

acer's picture

eval

This is called 2-argument eval, or evalat ("eval at", because it evaluates at some values). Notice that the instantiation can be obtained without having to actually assign to alpha. That can be useful because it leaves the original object as is, while also leaving name alpha unassigned and thus free immediately for continued symbolic use (no need to unassign it).

> eval(Result,alpha=Pi/2);
                                 [0    0    1]
                                 [           ]
                                 [1    0    0]
                                 [           ]
                                 [0    0    1]

I should mention that lowercase matrix and linalg are deprecated in favour of capitalized Matrix and LinearAlgebra.

acer

Hi, thanks a lot for your

Hi,

thanks a lot for your help....one further stupid question: I have noticed that If I say:

eval(Result, alpha = Pi/2), it calculates the matrix elements........

but when I say, for example,  eval(Result, alpha=Pi/10), then it shows me cos(pi/10).....I mean, not that I couldnt calculate this myself, but i find it unusal...

Thanks anyway ...:)

 

Trig functions of rational multiples of Pi

First, note that Maple interprets pi as a greek character with no special connotation. For the mathematical constant, use Pi instead.

As for the simplification of cos(Pi/2) versus cos(Pi/10), some rational multiples of Pi are treated automatically, while others are not because the resulting expression could be rather large. If you explicitly want that, try

convert(cos(Pi/10),radical);

acer's picture

convert, evalf

> R := Matrix([[cos(b/10),sin(b/10)]]);
                              [     b            b   ]
                         R := [cos(----)    sin(----)]
                              [     10           10  ]
 
> eval(R,b=evalf(Pi));
                        [0.9510565163    0.3090169944]
 
> evalf(eval(R,b=Pi));
                        [0.9510565163    0.3090169944]
 
> map(convert,eval(R,b=Pi),radical);
                     [ 1/2       1/2 1/2             1/2]
                     [2    (5 + 5   )               5   ]
                     [------------------    - 1/4 + ----]
                     [        4                      4  ]

acer

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}