
Is there a way to change the value of the transfer function through MATLAB & Simulink?
조회 수: 14 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Paul
2022년 12월 27일
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
추가 답변 (2개)
Sam Chak
2022년 12월 28일
Hi @영탁 한
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
Walter Roberson
2022년 12월 27일
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
Paul
2022년 12월 27일
편집: Paul
2022년 12월 27일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 General Applications에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

