Is there a way to change the value of the transfer function through MATLAB & Simulink?

6 vues (au cours des 30 derniers jours)
Can I change the value of the transfer function during simulation results?
If there is a transfer function of (1/as^2+bs+1), the values of a and b are changed from 0 to 5 seconds to a=1, b=3, and then after 5 seconds to a=2, b=4 how do you simulate this?
I'd like to print out the above value as one plot. using Fcn function in Simulink.
After writing the code in MATLAB, simulation is being conducted through simulink.

Réponse acceptée

Paul
Paul le 27 Déc 2022
Hi 영탁 한,
My interpretation of your question is that you really have a second order, time varying system. Such a system can't be represented with transfer functions. In Simulink, one way (though not the only way) is to implement the system using integrators and logic to control the value of the model parameters. The diagram below shows how to implement the system:
xdot = (-x + u)/a(t)
y = x;
where a(t) = a1 for t <= 5 and a(t) = a2 for t > 5. If you're using a variable step solver with the default settings, the solver will step exactly up to t = 5 to catch the switch.
If a(t) happened to be a constant, the transfer function would be: 1/(as + 1).
Modify this approach for your second order system.
  2 commentaires
영탁 한
영탁 한 le 28 Déc 2022
Thank you for your answer. I'll take that into consideration. Have a nice year-end.

Connectez-vous pour commenter.

Plus de réponses (2)

Sam Chak
Sam Chak le 28 Déc 2022
On top of the Paul's proposed solution in Simulink, here is one of few solutions in MATLAB.
If you like this solution, you may also vote 👍 the Answer.
% Simulation for Fixed system
G = tf(1, [1 3 1]); % a = 1, b = 3
step(G, 30)
hold on
% Simulation for Time-varying system
tspan = [0 30];
x0 = [0 0];
[t, x] = ode15s(@LTV, tspan, x0);
plot(t, x(:, 1), 'Color', [0.9290, 0.6940, 0.1250]),
ylim([0 1.2]), grid on, legend('fixed a', 'varied a')
hold off
t = linspace(0, 10, 1001);
a1 = 1;
a2 = 2;
a = a1 + (a2 - a1)*heaviside(t - 5);
b1 = 3;
b2 = 4;
b = b1 + (b2 - b1)*heaviside(t - 5);
plot(t, a, t, b), grid on, ylim([0 5]), xlabel('t'), legend('a', 'b')
% Time-varying system
function xdot = LTV(t, x)
xdot = zeros(2, 1);
a1 = 1;
a2 = 2;
a = a1 + (a2 - a1)*heaviside(t - 5);
b1 = 3;
b2 = 4;
b = b1 + (b2 - b1)*heaviside(t - 5);
Ref = 1;
xdot(1) = x(2);
xdot(2) = (- (x(1) - Ref) - b*x(2))/a;
end
  2 commentaires
영탁 한
영탁 한 le 28 Déc 2022
Thank you for your answer. I'll take that into consideration. Have a nice year-end.
Sam Chak
Sam Chak le 28 Déc 2022
Hi @영탁 한, same to you and wish you and family well in the New Year.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 27 Déc 2022
F until time t1 and then G can be achieved as F + (G minus F, delayed t1)
See the InputDelay parameters of tf(). Or if you constructing
s = tf('s')
G = something * exp(-DELAY*s)
and the exp will be recognized as delay
  6 commentaires
Paul
Paul le 27 Déc 2022
Modifié(e) : Paul le 27 Déc 2022
Referring to this comment ....
Let u(t) be the input to the system.
Let y0(t) be the output of f in response to u(t).
Let y2(t) be the output of f2 in respone to u(t).
Then, the output of h in response to u(t) is: y(t) = y0(t) - y0(t-5) + y2(t-5).
That may be what the OP wants, only the OP will know for sure.
영탁 한
영탁 한 le 28 Déc 2022
Thank you for your answer. I'll take that into consideration. Have a nice year-end.

Connectez-vous pour commenter.

Catégories

En savoir plus sur General Applications dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by