help, urgent: Error using DynamicSystem/lsim

11 vues (au cours des 30 derniers jours)
Schmittna59039
Schmittna59039 le 16 Mai 2016
Commenté : Walter Roberson le 16 Mai 2016
Hello I have a problem. I have a power train system, as an input I have torque with a constant slope and afte 0.4 seconds i need a constant torque. I realized it with a loop and if conditions. It doesn't work and I don't understand how to change my Code that there won't be an Error anymore.
This is the ERROR:
Error using DynamicSystem/lsim (line 84)
In time response commands, the time vector must be real, finite, and
must contain monotonically increasing and evenly spaced time samples.
Error in Antriebsstrang_Schmitt (line 99)
[y,t,x]=lsim(sys,h1,t);
THIS IS MY CODE:
% Antriebsstrang : Zustandsdarstellung
clear
clc
close all
% System-Parameter
J4 = 0.0784;
J2 = 0.000385;
J1 = 0.000271;
iG = 3.2;
iA = 4.1;
JM = 0.1322; % Motor, ...
cK = 1000;
MM = 90;
JA = J4+iA*iA*J2+iG*iA*iA*iA+J1 % Achswelle, ...
cA = 7300;
JF = 0.3426; % RAd, ...
JR = 1.0457; % Reifen, ...
cR = 31600;
% Systemmatrizen
J = [ JM 0 0 0;...
0 JA 0 0;...
0 0 JF 0;...
0 0 0 JR];
C = [cK (-cK*iG*iA) 0 0;...
(-iG*iA*cK) (-cK*iG*iG*iA*iA+cA) -cA 0;...
0 -cA cA+cR -cR;...
0 0 -cR cR];
% Lastverteilungsvektoren
p1 = [ 1;...
0;...
0;...
0 ]; % zu MM
% Matritzen für System- und Ausgangsgleichung & Modellaufbau
A = [ zeros(4,4) eye(4) ;...
-inv(J)*C -inv(J)*zeros(4,4) ]
B = [ zeros(4,1) ;...
inv(J)*p1 ]
Ca = [ 0 0 0 0 0 0 0 1 ] % phiR'
% phiM' phiM phiA' phiA phiF' phiF phiR' phiR
Da = [ 0 ]
%Loop and If-
for x=0:0.003:1.6;
if x< 0.4
t=datevec(x);
h1= 200*t ;
else
h1= 80;
h1=datevec(h1);
end
hold on
sys = ss(A, B, Ca, Da)
figure (1)
hold on
bode(sys)
%LSIM
[y,t,x]=lsim(sys,h1,t);
end
figure(2) %Ausgabe nach Anregung
figure (2)
plot(t, y);
xlabel('Zeit [s]');
ylabel('Beschleunigung [m/s^2]');
title('Beschleunigung')

Réponse acceptée

Star Strider
Star Strider le 16 Mai 2016
It is best to use a combination logical vector with conditions rather than a loop to create your input vector. My ‘h1’ assignment creates two logical vectors, one that is 1 (or true) for t<0.4, and zero elsewhere, multiplies it by 200*t (using element-wise multiplication) and adds it to another complementary vector calculated the same way to create the constant section. Note that logical true converts to numeric 1 in calculations, and false converts to numeric 0. (I plotted the ‘h1’ as a funciton of ‘t’ and it produces the result you describe as what you want.
The reason you are getting the error with your time vector is that datevec produces a 6-element vector for each time. This is not what you want for your simulation.
I added these lines to your code:
% Create ‘h1’ as logical vector with conditions on intervals — NEW CODE REPLACING ‘for’ LOOP AND ‘if’ BLOCK
x = 0:0.003:1.6; % Define ‘x’
t = x; % Define ‘t’
h1 = (200*t).*(t < 0.4) + 80*(t >= 0.4); % Create Input Vector
Your full code with my changes:
% System-Parameter
J4 = 0.0784;
J2 = 0.000385;
J1 = 0.000271;
iG = 3.2;
iA = 4.1;
JM = 0.1322; % Motor, ...
cK = 1000;
MM = 90;
JA = J4+iA*iA*J2+iG*iA*iA*iA+J1 % Achswelle, ...
cA = 7300;
JF = 0.3426; % RAd, ...
JR = 1.0457; % Reifen, ...
cR = 31600;
% Systemmatrizen
J = [ JM 0 0 0;...
0 JA 0 0;...
0 0 JF 0;...
0 0 0 JR];
C = [cK (-cK*iG*iA) 0 0;...
(-iG*iA*cK) (-cK*iG*iG*iA*iA+cA) -cA 0;...
0 -cA cA+cR -cR;...
0 0 -cR cR];
% Lastverteilungsvektoren
p1 = [ 1;...
0;...
0;...
0 ]; % zu MM
% Matritzen für System- und Ausgangsgleichung & Modellaufbau
A = [ zeros(4,4) eye(4) ;...
-inv(J)*C -inv(J)*zeros(4,4) ]
B = [ zeros(4,1) ;...
inv(J)*p1 ]
Ca = [ 0 0 0 0 0 0 0 1 ] % phiR'
% phiM' phiM phiA' phiA phiF' phiF phiR' phiR
Da = [ 0 ]
% Create ‘h1’ as logical vector with conditions on intervals — NEW CODE REPLACING ‘for’ LOOP AND ‘if’ BLOCK
x = 0:0.003:1.6; % Define ‘x’
t = x; % Define ‘t’
h1 = (200*t).*(t < 0.4) + 80*(t >= 0.4); % Create Input Vector
sys = ss(A, B, Ca, Da)
figure (1)
hold on
bode(sys)
%LSIM
[y,t,x]=lsim(sys,h1,t);
figure(2) %Ausgabe nach Anregung
figure (2)
plot(t, y);
xlabel('Zeit [s]');
ylabel('Beschleunigung [m/s^2]');
title('Beschleunigung')
figure(3)
plot(t, h1)
grid
axis([xlim 0 100])
title('Input Signal')
xlabel('Time (s)')
ylabel('Amplitude')
  2 commentaires
Schmittna59039
Schmittna59039 le 16 Mai 2016
Thank you so much. After having tried and failed for the whole the code finally works. Greetings Nadja
Star Strider
Star Strider le 16 Mai 2016
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (1)

Sebastian Castro
Sebastian Castro le 16 Mai 2016
First off, a tip: If you use "urgent" as part of your question, it makes people want to answer it less. Nobody gets special treatment here :)
Anyhow, I see two main issues with your code.
#1: I think the datevec portion where you define h1 and t is correct.
For example, the final values of t and h1 both end up being the vector 0 3 20 0 0 0, which creates the warnings you see. Time must be always increasing, but it goes from 20 back to 0!
My understanding is you want to generate a time vector that goes from 0 to 1.6 seconds. For the first 0.4 seconds, you will ramp up from 0 to 200*t = 80 and then hold the 80.
I would replace that whole section with:
t = 0:0.003:1.6;
h1 = 200*t;
h1(t>0.4) = 80;
#2: Your for-loop's end happens too late. I think you meant to add an extra end earlier in your code. Right now you're running the lsim command inside the for-loop, which is likely not what you want to do.
Of course, if you take my recommendation from #1, you won't need to use any for-loops here and you should just delete that end after the lsim command.
- Sebastian
  1 commentaire
Schmittna59039
Schmittna59039 le 16 Mai 2016
Hello Sebastian, thank you for your tip and your help. I will consider it next time :). I tried your solution too and it also works :).
Greetings Nadja

Connectez-vous pour commenter.

Catégories

En savoir plus sur Time and Frequency Domain Analysis dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by