MATLAB Help plotting transfer function in matlab

AI Thread Summary
The discussion revolves around issues with plotting a transfer function in MATLAB and performing matrix operations. The user is trying to superimpose two transfer functions but encounters errors related to matrix dimensions when executing the code. Key points include the need to ensure that the dimensions of matrices match for multiplication and the correct use of the transpose operator to align dimensions. Additionally, there is confusion about using the inverse function and the least squares method for finding the transfer function. The user seeks clarification on these MATLAB functionalities and requests code examples for the least squares method.
cupcake
Messages
73
Reaction score
0
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
 
Physics news on Phys.org
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

A.*X

assuming that X is a vector and A is a constant
 
ok now I have a variable Y which is a matric 49x1 and Phi which is a matric 50x2
when I perform this formula
theta=inv(Phi'*Phi)*Phi'*Y
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
 
cupcake said:
ok now I have a variable Y which is a matric 49x1 and Phi which is a matric 50x2
when I perform this formula
theta=inv(Phi'*Phi)*Phi'*Y
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

because inner matrix dimensions must agree. How would you multiply a 49 length vector with a 50 length vector even without a computer?
 
cupcake said:
ok now I have a variable Y which is a matric 49x1 and Phi which is a matric 50x2
when I perform this formula
theta=inv(Phi'*Phi)*Phi'*Y
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

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 can't 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).

Recall:

Code:
 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:
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...
 
or, anyone could give me the code for least square method??
 

Similar threads

Replies
8
Views
2K
Replies
4
Views
1K
Replies
4
Views
4K
Replies
2
Views
3K
Replies
5
Views
2K
Replies
1
Views
5K
Replies
1
Views
2K
Replies
3
Views
2K
Back
Top