Numerical simulation of a ODE with delay?

70 Views Asked by At

I often used to apply Euler Method to simulate an ODE, because it's a very simple method. Together with Euler Method I use a for loop.

The for loop might look like this:

x = x0 % initial state vector 
M = 1000 % Max step
For k = 1:M
    x = Ax + Bu(:, k)
    y(:, k) = Cx + Du(:, k)
End

This result a basic simulation of a linear ODE. But if I apply delay in this for loop, how should I do that?

I know that the input need to remember the past inputs. That's the point with the delay. If I do a step simulation of this simulation. I can just use:

u(:, k  - L)

Insted of:

u(:, k)

The L is a integer of delayed step and

$$ u(:, k - L) = 0 \forall k - L <= 0 $$

But now, the input u is going do be changed over every step because I am going to do a feedback simulation.

1

There are 1 best solutions below

0
On BEST ANSWER

I have the answer here:

I need to have the input as:

Input = [u(:,k) Input(1:(length(input) - 1))]

Then implementera that in:

x = x0 % initial state vector
Input = zeros(size(B,2), 10) % 10 seconds for delay if one step = 1 second
M = 1000 % Max step 
For k = 1:M
    Input = [u(:,k) Input(1:(length(input) - 1))]
    x = Ax + B*input(:, end) 
    y(:, k) = Cx + D*input(:, end) 
End

Now I got a delay.

For state feedback it is:

x = x0 % initial state vector 
Input = zeros(size(B,2), 10) % 10 seconds for delay if one step = 1 second
M = 1000 % Max step 
For k = 1:M
    Input = [F*x Input(1:(length(input) - 1))]
    x = Ax + B*input(:, end) 
    y(:, k) = Cx + D*input(:, end) 
End

Where F is the LQR controller gain matrix.