"Allen" <ajhalldeleteme@gmaildot.com> wrote in message
news:dil16r$k1e$1@news.ks.uiuc.edu...
> Hi again! [Guess it's twice in the same day.. sorry!]
>
> I was wondering if it's possible to make a matrix of functions in
> matlab. In other words:
>
> sin(theta) cos(theta)+cos(psi) 0
> cos(theta) sin(theta) 1
> 0 0 0
>
> That type of thing... If possible, then I can do simple matrix math
> with multiple matrixes like this, supplying the theta and psi as
> well...
>
> Now, I could do this all by hand, taking each index separately.
>
> But, I thought I'd check to ensure Matlab didn't have this
> capability first.
>
> Thanks!
> Allen
>
With symbolic toolbox you can do all of this easily.
As you know, with numeric Matlab, a variable needs to be a have a
value before it is referenced.
i.e. one can not write
F = m*a;
m=5; a=3;
but one must write
m5; a=3;
F=m*a;
With the symbolic toolbox, you can write as in the first case above,
i.e. one can have free variables, these are variables that are not
bounded to any value at the time they are encountered. (called syms in
Matlab)
For example, with extended symbolic toolbox, I could write
'R:=Matrix([
[sin(theta),cos(theta)+cos(psi),0],[cos(theta),sin(theta),1],[0,0,0]]
)'
Even thought at the time, theta, psi have no values.
Later on, one creates instances of this variable using different
values of psi and theta, without using functions, by simply
substituting different values for theta and psi each time as follows:
>> maple('with(LinearAlgebra)');
maple('Digits:=6');
maple('R:=Matrix([
[sin(theta),cos(theta)+cos(psi),0],[cos(theta),sin(theta),1],[0,0,0]]
)');
maple('A:=subs({theta=Pi/2,psi=Pi/4},R)');
maple('B:=subs({theta=Pi/8,psi=Pi/8},R)');
maple('convert(evalf(A+B),listlist)')
ans =
[[1.38268, 2.55487, 0.], [.923880, 1.38268, 2.], [0., 0., 0.]]
>>
Nasser
