Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help! plotting transfer function in matlab

  1. Oct 11, 2010 #1
    Hello, I need a help here, cause I only have basic matlab.. I want to superimpose two transfer function,

    Gp(s)=(Kp/sT+1)*e^(-sL) in frequency domain,
    in time domain y(t)=Kp*(1-exp(t-T)/L)*1(t-L)
    where, the value of Kp, T and L are known.. and t is matric time from 0-24.5 [0, 0.5, 1....24.5]

    how to write y(t) in matlab code? when I just wrote the y(t) as I wrote above, I got this error msg : Error using ==> mtimes
    inner matrix dimensions must agree
  2. jcsd
  3. Oct 11, 2010 #2


    User Avatar
    Gold Member

    anywhere you have an multiplication or division operation on a vector, you have to specify how you want it multiplied. In your case, you have to a put a period '.' in front of each case of multiplication and division, so that you have


    assuming that X is a vector and A is a constant
  4. Oct 11, 2010 #3
    ok now I have a variable Y which is a matric 49x1 and Phi which is a matric 50x2
    when I perform this formula
    I got this error again
    ??? Error using ==> mtimes
    Inner matrix dimensions must agree.

    can anyone advise? how to use inverse function? also not very sure about "....'...." there
  5. Oct 12, 2010 #4


    User Avatar
    Gold Member

    because inner matrix dimensions must agree. How would you multiply a 49 length vector with a 50 length vector even without a computer?
  6. Oct 12, 2010 #5
    I suspect you are not using the same time interval for Phi and Y since Phi is one unit longer.

    Secondly, you should only be using the "...'..." function to switch the dimensions of your vector (eg, if X is a vector with dimensions [5,1] then X' is a vector with dimensions [1,5]); I typically do this (when appropriate) to make the inner matrix dimensions agree (eg, you cant multiply a matrix with dimension [5,1] by one that is [1,5]; so you can NOT multiply X.*X' because the dimensions do not match).

    What is the meaning of your equation where you have inv(Phi.*Phi')? It looks like you are trying to use the definition AND function of an inverse matrix. First of all, your matrix MUST be square to do this [eg, dimension [2,2], or [3,3], etc).


    Code (Text):
     A = [a,b; c,d];
    Inverse = A*A^-1;
    Inverse = 1/|A|*[a,-b;-c,d];
    |A| = a*d-b*c;

    so if

    a = [1,2;3,4];
    % where the mag of a is 1*4-2*3 = -2;
    b = inv(a)
    b = [-2,1; 1.5,-.5]
    Hope that is somewhat helpful!
    Last edited: Oct 12, 2010
  7. Oct 12, 2010 #6
    I was bluntly given the mat lab code, so I don't know exactly what's going on, what they need me to do is now like changing the variables.. actually that formula is for finding the transfer function by using least square method...
  8. Oct 12, 2010 #7
    or, anyone could give me the code for least square method??
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook