Using Lsim to solve a dynamic control model.

35 views (last 30 days)
ayman hussien
ayman hussien on 12 Dec 2020
Commented: Paul on 15 Dec 2020
Hi All.
I am trying to use lsim to solve a dynamic model with a differentiated input.
the way i did it on simulink was through a differentiation block.
on matlab i tried the following.
t = 0:0.006:15;
for i = 1:length(t)
if t(i) >= 1 %Front wheel bump at 1 seconds
wf(1,i) = 0.1;
end
if t(i) >= 5 %Rear wheel bump at 5 seconds
wf (2,i) = 0.1;
end
end
% input differentiation
wf1 = wf (1,:); wf2 = wf (2,:);
w = [gradient(wf1)./gradient(t) ; gradient(wf2)./gradient(t) ];
Susp_sys = ss((A-B*K),G,C,D);
[Y,T,x] = lsim (Susp_sys,w,t);
but the numerical result of both simulations aren't close.
i was wondering if their is a difference between Simulink derivative and the way i am using a derivative here. and if there is how can i ammend that.
The way i am doing sample time maybe ?

Answers (1)

Paul
Paul on 12 Dec 2020
It sounds like wf1 and wf2 are supposed to be step inputs at t = 1 and t = 5. In Simulink these were implemented with Step blocks each followed by a Derivative block. Try replacing the Derivative blocks with Transfer Function blocks of the form:
s/(tau*s + 1)
where tau is suitably small. You might have to experiment with tau. As tau gets smaller, the solution will be more accurate but the simulation will run slower. Make sure the simulation is using a variable step solver and that the max step size is either auto or a small number. Might need to experiment with this parameter as well.
Another alternative would be to absorb the differentiation into downstream elements of the model. Wheter or not this is feasible depends on how the model is structured.
On the Matlab side, taking that numerical gradient might work. But the derivative of the step function is the Dirac delta function, so you can just as easily use the impulse function for each input, shift the outputs to the times the steps occur, and then sum the results.
  2 Comments
ayman hussien
ayman hussien on 15 Dec 2020
Thank you for your suggestion and i apologise for trying it out late.
i tried your suggestion as
impulse = t_j == 1; impulse2 = t_j ==5;
w = (1/h)*[ impulse; impulse2];
the reason i multiply by 1/h ( which is my time sample) is that i need to exclude the effect of the time sampling value.
while the results are better they are still not close to those of simulink, which i found satisfying and considered accurate.
i am yet to try your suggestion for the simulink model. but i was satisfied already with the results presented by the dirreivative block. is their something wrong bout relying on it?
Thanks a lot for your help.
Paul
Paul on 15 Dec 2020
I wouldn't use the Derivative block to take the derivative of a discontinuous signal.
As for doing it all in Matlab, here's an example asusming that your system has two inputs and one output.
First, define the time vector and the inputs as a function of time:
>> t=0:.001:15;
>> for i = 1:length(t)
if t(i) >= 1 %Front wheel bump at 1 seconds
wf(1,i) = 0.1;
end
if t(i) >= 5 %Rear wheel bump at 5 seconds
wf (2,i) = 0.1;
end
end
Define a 2-input, 1-output state space model for this example:
sys=minreal(ss([tf(2,conv([1 3],[1 1])) tf(1,conv([1 3],[1 2]))]))
Define the respons of the system to the inputs wf:
y=lsim(sys,wf,t);
However, we really want the output in response to the derivative of the input. But the output in response to the derivative of wf is the same as the derivative of the output in response to wf
yd=gradient(y(:),t(:));
Alternatively, we know the the inputs wf are step inputs at t = 1 and t = 5. The derivative of the step input is the delta function. So we want the output of the system in response to a delta function in the first input delayed by 1 second and to a delta function in the second input delayed by 5 seconds. There are a few ways to do this. Here's one. Note that we have to scale by 0.1 because the steps in wf are to 0.1
>> s=tf('s');
>> ydimp=impulse(0.1*series(blkdiag(exp(-s),exp(-5*s)),sys),t);
ydimp is the response to each input separately. What we really want is the sum of those:
>> ydimp = sum(ydimp,3);
Compare the results:
>> plot(t,yd,t(1:100:end),ydimp(1:100:end),'x'),grid
yd and ydimp are the outupt of the system sys in response to the derivative of wf.

Sign in to comment.

Categories

Find more on General Applications in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!