Search code examples
matlablinear-algebrasymbolic-math

Using unspecified constants in matlab


I'm trying to solve a system of equations in the s-domain. So set up this system of equations in matrix form:

a=[.4*s+s+5 -5; -5 .5*s+5]  
c=[3/s; 3/(2*s)]  
(1/s)*a*b=c

I just get the error that s is undefined. How can I solve for b in terms of s?


Solution

  • Matlab does not (naturally) do symbolic calculations --- which is what your code is trying to do. Matlab's variables need to be concrete numbers, or arrays, or structures, etc. They cannot just be placeholders for arbitrary numbers.

    (UNLESS: You use the symbolic computing toolbox for Matlab. I haven't really used this because I prefer to do symbolic computing in environments such as Maple or Mathematica. You could even solve your problem on the Wolfram Alpha website)

    But if you pick a specific value of s, computing what you want is easy:

    s = 5;
    a=[.4*s+s+5 -5; -5 .5*s+5];
    c=[3/s; 3/(2*s)];
    b = s*(a\c);
    

    Where I have used the backslash operator for doing linear inversion.

    You should now have that

    (1/s)*a*b-c
    

    is the zero vector.

    EDIT: I looked into the symbolic toolbox. It looks like this is what you want (but you need to have the symbolic toolbox licensed and installed for it to work):

    syms s;
    a=[.4*s+s+5 -5; -5 .5*s+5];
    c=[3/s; 3/(2*s)];
    b = simple(s*(a\c))