Help plotting transfer function in matlab

Click For Summary

Discussion Overview

The discussion revolves around issues related to plotting transfer functions in MATLAB, specifically focusing on the implementation of mathematical formulas and matrix operations. Participants are seeking assistance with coding and resolving errors encountered during calculations involving transfer functions and least squares methods.

Discussion Character

  • Technical explanation
  • Homework-related
  • Mathematical reasoning

Main Points Raised

  • One participant seeks help with MATLAB code for superimposing two transfer functions and expresses confusion over an error related to matrix multiplication.
  • Another participant suggests using element-wise operations by adding a period before multiplication and division to resolve vector-related errors.
  • Multiple participants report encountering the same error regarding inner matrix dimensions not agreeing when attempting to compute a variable using the inverse function.
  • There is a discussion about the importance of ensuring that the dimensions of matrices are compatible for multiplication, with one participant questioning the validity of the operations being performed.
  • One participant expresses uncertainty about the purpose of the inverse function and the notation used in the MATLAB code provided to them.
  • A request is made for a complete code example for implementing the least squares method in MATLAB.

Areas of Agreement / Disagreement

Participants generally agree on the nature of the errors encountered in MATLAB related to matrix dimensions, but there is no consensus on the correct approach to resolve these issues or on the specifics of the least squares method implementation.

Contextual Notes

Participants mention specific matrix dimensions and operations, indicating potential limitations in understanding the underlying mathematical concepts and the need for clarity on MATLAB syntax and functions.

Who May Find This Useful

This discussion may be useful for individuals working with MATLAB, particularly those dealing with transfer functions, matrix operations, and least squares methods in a technical or academic context.

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 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K