Change value of parameters in simulink over time
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am simulating a complex system and have a trouble. However, I will explain my problems by similar case.
Assuming I have a following system:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1429833/image.png)
with a1, a2, a4, a5 are functions depending on u, v. For example, a1 = u*v; a2 = u+v; a4 = u-v; a5 = u/v (in fact, they are more bulky).
I want to change values u, v in a certain domain over time, it leads to a1, a2, a3, a4 are changed values. But, I don't know how to do.
Please help me. Thank you.
Réponses (2)
Deep
le 9 Juil 2023
You can use a 'clock' and model your u,v signals as functions of the simulation time. For modeling complex and bulky math functions, a 'MATLAB function' block can help you write big functions as MATLAB code.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430023/image.png)
You can double click on the MATLAB function blocks to edit your functions.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430028/image.png)
0 commentaires
Sam Chak
le 9 Juil 2023
If the parameters
in the transfer function vary over time, then it is a nonlinear system. Nonlinear systems need to be modeled in the equivalent continuous-time state differential equations. In your case, the system output is
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430033/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430038/image.png)
Equivalent state differential equations and system output:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430043/image.png)
Substituting the parameters for
as the time-varying functions of auxiliary inputs
and ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430058/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430048/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430053/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430058/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430063/image.png)
Since the system input
is given, then the overall model becomes
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430068/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430073/image.png)
In Simulink, if you are using basic blocks, then the system needs to be expressed in the Integral form. In other words, you need to construct the integrands (right-hand side of the ODEs) and then feed them into the input ports of the Integrator blocks.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430078/image.png)
The outputs of the Integrator blocks are the states
, and they can be fed back into the integrands.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430083/image.png)
Example:
The following example assumes that the parameters
are constants. But I think that you should get the idea.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1430088/image.png)
% Parameters
a1 = 7;
a2 = 5;
a4 = 3;
a5 = 2;
params = [a1 a2 a4 a5];
% Transfer function of the Plant
G = tf([a1 a2], [1 a4 a5])
tspan = linspace(0, 6, 60001);
x0 = [0 0];
[t, x] = ode45(@(t, x) odefcn(t, x, params), tspan, x0);
% Solution Plot
subplot(2, 1, 1)
plot(t, x(:,1), 'color', 'r'), grid on, ylabel('Amplitude')
title('Time response of Output, y(t)')
subplot(2, 1, 2)
step(G), grid on
function xdot = odefcn(t, x, params)
xdot = zeros(2, 1);
a1 = params(1);
a2 = params(2);
a4 = params(3);
a5 = params(4);
w = heaviside(t); % step input
xdot(1) = x(2) + a1*w;
xdot(2) = - a5*x(1) - a4*x(2) + (a2 - (a1*a4))*w;
end
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!