write Simulink block diagram to source code
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/736639/image.png)
How to write this in matlab source code instead of using Simulink?
Antworten (1)
Pravarthana P
am 14 Feb. 2022
Bearbeitet: Pravarthana P
am 14 Feb. 2022
Hi Olivia, it can be understood from the figure and your query that you are trying to write MATLAB code equivalent to the closed loop mentioned above.
To begin with try reducing the first block to have a common denominator. Then it will be easy to code the transfer function in MATLAB using the tf() function using the following link Transfer function.
For example, I am assuming first block as G1 and second block as G2:
G1 can be re-written as:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/893740/image.png)
This can be written using tf()as:
G1 = tf([
],[ 0
0]).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/893745/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/893750/image.png)
G2 can also the reduced in the same manner. Assign
G=G1*G2
Next step will be to convert the closed loop to code, you can find information related to closed loop in the following link: Using FEEDBACK to Close Feedback Loops - MATLAB & Simulink Example (mathworks.com)
To help with the process try the following documentations:
1 Kommentar
Walter Roberson
am 14 Feb. 2022
Be careful though: Simulink will not accept the first of those transfer functions
syms K_c2 K_p2 s tau_D tau_I tau_p2 theta_p2
G1 = collect(K_c2 * (1 + 1/(tau_I * s) + tau_D * s), s)
Notice that the numerator has s powers up to
but the denominator has at most s . That situation is not permitted for transfer functions within Simulink (the documentation says something about it being non-casual when it happens.)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/894225/image.png)
G2 = K_p2 * exp(-theta_p2*s)/(tau_p2 * s + 1)
H = G1 * G2
[N, D] = numden(H)
num = N
den = collect(D, s)
Okay, so the composite function H has up to
in the numerator and also in the denominiator, and that is acceptable.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/894260/image.png)
The
in Laplace Transform theory matches to a delay of
units.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/894265/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/894270/image.png)
Siehe auch
Kategorien
Mehr zu Simulink Functions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!