How can constraint varaibles in my fcn simulink block?

1 view (last 30 days)
This is my block:
This is the function inside it:
function xdot = fcn(x,u)
delta=1;
x1=x(1);
x2=x(2);
xdot1=x1*x2-delta*x1;
xdot2=-x1*x2-x2+u;
xdot=[xdot1;xdot2];
end
The value is dimensionless and normalized the maximum value could be 1 for both variables. But when I control it the second variable goes to the moon and it does not have physical sense.
I try to use saturation but I am not proud of the result. Could you advise some strategy to put some constrain in my fcn block?

Accepted Answer

Sam Chak
Sam Chak on 5 Oct 2023
The analysis shows that the constraint on control action is unnecessary. In Case 1, the control-free system () has two equilibrium points, with the stable one at the origin and the unstable one at . If the initial conditions are carefully selected such that and , then the trajectories are guaranteed to converge to the origin.
However, it is always desirable to find an easily implementable control action, denoted as u, such that the nonlinear system will converge to the equilibrium point from any possible starting non-equilibrium point. Since the control action is not provided, three types of control actions, , , and , in Case 2, are proposed, and the equilibrium at the origin is globally stable.
%% Finding equilibrium point
fun = @f; % function (refer to Nonlinear System)
x0 = [-2, 2]; % initial guess
z = fsolve(fun, x0)
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
z = 1×2
-1.0000 1.0000
[x1, x2] = meshgrid(-2:2);
delta = 1;
%% Case 1: Stream Plot of Control-free system
u = 0;
U = x1.*x2 - delta*x1;
V = - x1.*x2 - x2 + u;
figure(1)
l = streamslice(x1, x2, U, V); set(l, 'Color', '#c3829e');
xlabel({'$x_{1}$'}, 'interpreter', 'latex', 'fontsize', 12)
ylabel({'$x_{2}$'}, 'interpreter', 'latex', 'fontsize', 12)
title('Stream Plot of Control-free System')
axis tight
%% Case 2: Stream Plot of Control system
u1 = x1; % type-1 control action
u2 = x1 - x2; % type-2 control action
u3 = - (x1.^2 - x1.*x2); % type-3 control action
U = x1.*x2 - delta*x1;
V = - x1.*x2 - x2 + u3;
figure(2)
l = streamslice(x1, x2, U, V);
xlabel({'$x_{1}$'}, 'interpreter', 'latex', 'fontsize', 12)
ylabel({'$x_{2}$'}, 'interpreter', 'latex', 'fontsize', 12)
title('Stream Plot of Control System')
axis tight
%% Testing the system using Type-3 control action
tspan = [0 10];
x0 = [-2 2]; % divergent in the control-free system
[t, x] = ode45(@odefcn, tspan, x0);
figure(3)
plot(t, x, 'linewidth', 1.5), grid on
xlabel({'$t$'}, 'interpreter', 'latex', 'fontsize', 12)
ylabel({'$\mathbf{x}(t)$'}, 'interpreter', 'latex', 'fontsize', 12)
legend({'$x_{1}(t)$', '$x_{2}(t)$'}, 'interpreter', 'latex', 'fontsize', 14)
title({'Time responses under $u = - x_{1}^{2} + x_{1} x_{2}$'}, 'interpreter', 'latex', 'fontsize', 16)
%% Nonlinear System (for finding the equilibrium)
function y = f(x)
y = zeros(2, 1);
delta = 1;
y(1) = x(1)*x(2) - delta*x(1);
y(2) = - x(1)*x(2) - x(2);
end
%% Nonlinear ODEs
function dxdt = odefcn(t, x)
dxdt = zeros(2, 1);
delta = 1;
u = - (x(1)^2 - x(1)*x(2)); % Type-3
dxdt(1) = x(1)*x(2) - delta*x(1);
dxdt(2) = - x(1)*x(2) - x(2) + u;
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!