## Resetting only a section of my state during event driven ode45 simulation

Hello,

I’m trying to write a code that simulates a closed loop event driven LTI system (with a poleplacement controller u(t) = -K*x(t)). I’m using the following event formulation:

where the stands for the actual state and the stands for the error between the current state and the state measured during an event trigger. So:

So I want to trigger an event the moment the value becomes 0.

Now, the problem I’m having is that I want the value (so the error) to reset to 0 upon an event but the part of the state should not reset. I’m having trouble coming up with a way to exactly program this. I’m currently just simulating the system dynamics for the augmented system, so for . For now I have the following in matlab:

a = 4;

b = 6;

c = 9;

poles = [-1+2i; -1-2i];

A = [0.3+a-b, 0.5-c; 0, 1];

B = [0; 1];

C = eye(2);

D = [0; 0];

K = place(A, B, poles);

A_aug = [A-B*K -B*K;

-A+B*K B*K];%Defining augmented CL A-matrix for augmented state x_augmented = [x;error]//[xi;epsilon]

tspan = [0,10];

x0 = [1;1;0;0];

Q = eye(2);

P = 2*eye(2);

sig = 0.1;

options = odeset(‘Events’, @(t,x) myEventsFcn(t,x,sig,Q,P,B,K));

[t,y,te,ye,ie] = ode45(@(t,x) LTIaug_fun(t,x,A_aug),tspan,x0,options)

Where the LTIaug_fun and myEventsFcn are defined as follows:

function dxdt = LTIaug_fun(~,x,A_aug)

dxdt = A_aug*x;

end

function [value,isterminal,direction] = myEventsFcn(t,x,sig,Q,P,B,K)

Th = [(1-sig)*Q P*B*K;

(B*K)’*P zeros(2,2)];

Th_e = x’*Th*x;

value = Th_e;

isterminal = 1;

direction = 0;

end

So how do I set my part of my augmented state to 0 after/during an event trigger?Hello,

I’m trying to write a code that simulates a closed loop event driven LTI system (with a poleplacement controller u(t) = -K*x(t)). I’m using the following event formulation:

where the stands for the actual state and the stands for the error between the current state and the state measured during an event trigger. So:

So I want to trigger an event the moment the value becomes 0.

Now, the problem I’m having is that I want the value (so the error) to reset to 0 upon an event but the part of the state should not reset. I’m having trouble coming up with a way to exactly program this. I’m currently just simulating the system dynamics for the augmented system, so for . For now I have the following in matlab:

a = 4;

b = 6;

c = 9;

poles = [-1+2i; -1-2i];

A = [0.3+a-b, 0.5-c; 0, 1];

B = [0; 1];

C = eye(2);

D = [0; 0];

K = place(A, B, poles);

A_aug = [A-B*K -B*K;

-A+B*K B*K];%Defining augmented CL A-matrix for augmented state x_augmented = [x;error]//[xi;epsilon]

tspan = [0,10];

x0 = [1;1;0;0];

Q = eye(2);

P = 2*eye(2);

sig = 0.1;

options = odeset(‘Events’, @(t,x) myEventsFcn(t,x,sig,Q,P,B,K));

[t,y,te,ye,ie] = ode45(@(t,x) LTIaug_fun(t,x,A_aug),tspan,x0,options)

Where the LTIaug_fun and myEventsFcn are defined as follows:

function dxdt = LTIaug_fun(~,x,A_aug)

dxdt = A_aug*x;

end

function [value,isterminal,direction] = myEventsFcn(t,x,sig,Q,P,B,K)

Th = [(1-sig)*Q P*B*K;

(B*K)’*P zeros(2,2)];

Th_e = x’*Th*x;

value = Th_e;

isterminal = 1;

direction = 0;

end

So how do I set my part of my augmented state to 0 after/during an event trigger? Hello,

I’m trying to write a code that simulates a closed loop event driven LTI system (with a poleplacement controller u(t) = -K*x(t)). I’m using the following event formulation:

where the stands for the actual state and the stands for the error between the current state and the state measured during an event trigger. So:

So I want to trigger an event the moment the value becomes 0.

Now, the problem I’m having is that I want the value (so the error) to reset to 0 upon an event but the part of the state should not reset. I’m having trouble coming up with a way to exactly program this. I’m currently just simulating the system dynamics for the augmented system, so for . For now I have the following in matlab:

a = 4;

b = 6;

c = 9;

poles = [-1+2i; -1-2i];

A = [0.3+a-b, 0.5-c; 0, 1];

B = [0; 1];

C = eye(2);

D = [0; 0];

K = place(A, B, poles);

A_aug = [A-B*K -B*K;

-A+B*K B*K];%Defining augmented CL A-matrix for augmented state x_augmented = [x;error]//[xi;epsilon]

tspan = [0,10];

x0 = [1;1;0;0];

Q = eye(2);

P = 2*eye(2);

sig = 0.1;

options = odeset(‘Events’, @(t,x) myEventsFcn(t,x,sig,Q,P,B,K));

[t,y,te,ye,ie] = ode45(@(t,x) LTIaug_fun(t,x,A_aug),tspan,x0,options)

Where the LTIaug_fun and myEventsFcn are defined as follows:

function dxdt = LTIaug_fun(~,x,A_aug)

dxdt = A_aug*x;

end

function [value,isterminal,direction] = myEventsFcn(t,x,sig,Q,P,B,K)

Th = [(1-sig)*Q P*B*K;

(B*K)’*P zeros(2,2)];

Th_e = x’*Th*x;

value = Th_e;

isterminal = 1;

direction = 0;

end

So how do I set my part of my augmented state to 0 after/during an event trigger? ode45, event based control MATLAB Answers — New Questions