0
votes

I have a differential equation: dx/dt = a * x. Using Matlab Simulink, I need to solve this equation and output it using Scope block.

The problem is, I don't know how to specify an initial condition value t = 0.

So far I have managed to create a solution that looks like this:

Model

I know that inside integrator, there is a possiblity to set "Initial condition" but I can't figure out how that affects the final result. How can I simply set the value of x at t = 0; e.i. x(0) = 6?

2
Why are you using a Gain block with a value of 1? This does nothing... You should have a Memory block to defer the feedback loop by 1 timestep. And why does setting the initial condition inside the block not achieve what you want?Wolfie
I thought using gain with value 1 means setting a to 1. e.i. gain = 5 <=> a = 5. Was I wrong? The second question: what happens if I set initial condition to 5, does it mean x(0) = 5 ?Mark
A gain is a multiplier, so you are taking the output of your integrator, multiplying it by 1, and feeding it back into your integrator. Note, because you are not using a Memory block to interrupt the feedback, you are trying to use the instantaneous output also as the input, which won't work. And yes, that's what an initial condition isWolfie
@Wolfie, there is no need for a memory block in this model. @Mark, you are correct that the gain block represent the a in your model, and that setting the Initial Condition to 5 does mean that x(0)=5. In most instances a will be negative, leading to a converging/decaying response.Phil Goddard

2 Answers

1
votes

Let's work this problem through analytically first so we know if the model is correct.

   dx/dt = a*x       % Seperable differential equation
=> (1/x) dx = a dt   % Now we can integrate
=> ln(x)  = a*t + c  % We can determine c using the initial condition x(0)
=> ln(x0) = a*0 + c
=> ln(x0) = c 
=> x = exp(a*t + ln(x0)) % Subbing into 3rd line and taking exp of both sides
=> x = x0 * exp(a*t)

So now we have an idea. Let's look at this for t = 0 .. 1, x0 = 6, a = 5:

% Plot x vs t using plain MATLAB
x0 = 6; a = 5; 
t = 0:1e-2:1; x = x0*exp(a*t);
plot(t,x)

figure


Now let's make a Simulink model which acts as a numerical integrator. We don't actually need the Integrator block for this application, we simply want to add the change at each time step!

model

To run this, we must first set a couple of things up. In Simulation > Model Configuration Parameters, we must set the time step to match the time step we've used to switch between dx/dt and dx (2nd Gain block).

config

Lastly, we must set the initial condition for x0, this can be done in the Memory block

initial

Setting the end time to 1s and running the model, we see the expected result in the Scope. Because it matches our analytical solution, we know it is correct.

scope


Now we understand what's going on, we can re-introduce the integration block to make the model more flexible. Using the integrator means that dt is automatically calculated, and we don't need to micro-manage the Gain block, in fact we can get rid of it. We still need a Memory block though. We now also need intial conditions in both the integrator, and the memory block. Put scopes in different locations and just complete the first few time steps to work out why!

simple

Note that the initial conditions are less clear when using the integrator block.

0
votes

The way to think about the integrator blocks is either completely in the Laplace picture, or as representing the equivalent integral equation for the IVP

y'(t)=f(t,y(t)),  y(0) = y_0

is equivalent to

y(t) = y_0 + int(s=0 to t) f(s,y(s)) ds

The feed-back loop in the block diagram realizes almost literally this fixed-point equation for the solution function.

So there is no need for complicated constructions and extra blocks.