Help plotting transfer function in matlab

In summary, the person is asking for help with MATLAB code and is unsure about how to use the inverse function. They are also confused about the meaning of the equation. The equation is used to find the transfer function. The person is looking for help with the least square method.
  • #1
cupcake
76
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
  • #2
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
 
  • #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
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
 
  • #4
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?
 
  • #5
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:
  • #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...
 
  • #7
or, anyone could give me the code for least square method??
 

What is a transfer function?

A transfer function is a mathematical representation of the relationship between the input and output of a system. It describes how the output of a system changes in response to changes in the input, and is commonly used in control systems and signal processing.

How can I plot a transfer function in MATLAB?

To plot a transfer function in MATLAB, you can use the "tf" function to define the transfer function and then use the "bode" or "nyquist" functions to plot the frequency response. You can also use the "pzmap" function to plot the poles and zeros of the transfer function.

What is the syntax for defining a transfer function in MATLAB?

The syntax for defining a transfer function in MATLAB is:
tf = tf(num, den)
where "num" is a vector representing the coefficients of the numerator polynomial and "den" is a vector representing the coefficients of the denominator polynomial.

Can I customize the plot of a transfer function in MATLAB?

Yes, you can customize the plot of a transfer function in MATLAB by using various options in the "bode" or "nyquist" functions. These options allow you to change the color, line style, and range of the plot, as well as add labels and legends.

Is it possible to simulate a transfer function in MATLAB?

Yes, it is possible to simulate a transfer function in MATLAB by using the "lsim" function. This function allows you to input a desired input signal and simulate the output of the transfer function in the time domain.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
987
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
Back
Top