help, urgent: Error using DynamicSystem/lsim
Mostra commenti meno recenti
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')
Risposta accettata
Più risposte (1)
Sebastian Castro
il 16 Mag 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 Commento
Schmittna59039
il 16 Mag 2016
Categorie
Scopri di più su Time and Frequency Domain Analysis in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!