0

I have 3 matrix:

T_01 = ['cosd*t1', '-sind*t1', '0', 'd1*cosd*t1'; 'sind*t1', 'cosd*t1', '0', 'd1*sind*t1'; '0', '1', '1', '0'; '0', '0', '0', '1']

T_12 = ['cosd*t2', '-sind*t2', '0', 'd2*cosd*t2'; 'sind*t2', 'cosd*t2', '0', 'd2*sind*t2'; '0', '1', '1', '0'; '0', '0', '0', '1']

T_23 = ['cosd*t3', '-sind*t3', '0', 'd3*cosd*t3'; 'sind*t3', 'cosd*t3', '0', 'd3*sind*t3'; '0', '1', '1', '0'; '0', '0', '0', '1']

I need to make a symbolic multiplication, so I'm trying:

mulf(T_01,T_12,T_23)

But I get this error:

                     !--error 39 
mulf: Quantidade incorreta de argumentos de entrada: esperava-se 2.

What is happening?

Obs.: Sorry for my english.

1
  • The mulf function only takes 2 arguments. Since multiplications is associative, i.e. abc = a*(b*c), you could try mulf(T_01, mulf(T_12, T_23)). Then again, you'll get another error, because a matrix cannot be an input of this function. What exactly do you want to do? Can you clarify? Maybe you can tell us what is the result you expected to get. Oct 21, 2017 at 23:49

1 Answer 1

0

If what you want is to get the symbolic multiplication of two matrix, you'll have to implement such function. Here I've implemented three functions that together can perform what you want:

function s = scaProd(a,b)
    //escalar product of two vectors
    //using recursion

    if (a == [] | b == []) then
       s = ""

    elseif (max(size(a)) ~= max(size(b))) | ...
           (min(size(a)) ~= min(size(b))) | ...
           (min(size(a)) ~= 1) then
        error("vectorMulf: Wrong dimensions")

    else
        s = addf( mulf(a(1), b(1)) , scaProd(a(2:$), b(2:$)) )

    end
endfunction

function s = matrixMulf(a,b)
    //matrix multiplication

    acols = size(a,'c');
    brows = size(b,'r');
    if acols ~= brows then
        error("matrixMulf: Wrong dimensions")
    end

    arows = size(a,'r');
    bcols = size(b,'c');
    s = string(zeros(arows,bcols));

    for i = 1 : arows
        for j = 1 : bcols
            s(i,j) = scaProd(a(i,:),b(:,j)');
        end
    end
endfunction

function s = addP(a)
    //encolses each element of a in a pair of parenthesis
    s = string(zeros(a));

    for i = 1 : size(a,'r')
        for j = 1 : size(a,'c')
            s(i,j) = "(" + a(i,j) + ")"
        end
    end
endfunction

Here is an example of it's output. Test code:

A = [1 2; 3 4];
B = [5 6; 7 8];
C = [9 0; 1 2];
disp(A*B*C)
As = string(A);
Bs = string(B);
Cs = string(C);
disp(matrixMulf(As,addP(matrixMulf(Bs, Cs))))

Console output:

   193.   44. 
   437.   100.

!1*(5*9+6*1)+2*(7*9+8*1)  1*(5*0+6*2)+2*(7*0+8*2)  !
!                                                  !
!3*(5*9+6*1)+4*(7*9+8*1)  3*(5*0+6*2)+4*(7*0+8*2)  !

For the result you want, you should do:

  1. Enclose every term of each of your matrices with parenthesis using addP()
  2. Perform the symbolic multiplication like matrixMulf(t1,addP(matrixMulf(t2,t3))), where t1, t2, t3 are the enclosed versions of your matrices.

And two final notes:

  • It is important to use addP at each multiplication step to get the correct result. You can check that by removing the ( and ) in the example I gave: the result won't be correct.
  • The functions mulf and addf are not available on Scilab 6.0.0. So remember you won't be able to use them if you upgrade your Scilab to the current stable version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.