Giving a rectangular pulse in ode45
古いコメントを表示
I am trying to use a rectangular pulse in my system through ode 45, so I decided to split my code and run it 3 times. Once at 0, then at 1 and at 0 again. I am not getting results as expected. As you can see, I have a system code as:
clear all
%%
%paramters of leader vehicle
q=0; %position
v=0; %velocity
a=0; %acceleration
x_0=[q;
v;
a]; %initial conditions
t=linspace(0,5,100);
%parameters of second vehicle
q1=0; %position
v1=0; %velocity
a1=0; %acceleration
x_1=[q1;
v1;
a1]; %initial conditions
%parameters of third vehicle
q2=0; %position
v2=0; %velocity
a2=0; %acceleration
x_2=[q2;
v2;
a2]; %initial conditions
%initial conditions of the platoon
x=[x_0; x_1; x_2];
[t,y1]=ode45(@code,t,x);
%% second step
%paramters of leader vehicle
q=1; %position
v=0; %velocity
a=0; %acceleration
x_0=[q;
v;
a]; %initial conditions
t=linspace(5,50,100);
%parameters of second vehicle
q1=0; %position
v1=0; %velocity
a1=0; %acceleration
x_1=[q1;
v1;
a1]; %initial conditions
%parameters of third vehicle
q2=0; %position
v2=0; %velocity
a2=0; %acceleration
x_2=[q2;
v2;
a2]; %initial conditions
%initial conditions of the platoon
x=[x_0; x_1; x_2];
[t,y2]=ode45(@code,t,x);
%% third step
%paramters of leader vehicle
q=0; %position
v=0; %velocity
a=0; %acceleration
x_0=[q;
v;
a]; %initial conditions
t=linspace(50,60,100);
%parameters of second vehicle
q1=y2(end,4); %position
v1=0; %velocity
a1=0; %acceleration
x_1=[q1;
v1;
a1]; %initial conditions
%parameters of third vehicle
q2=y2(end,7); %position
v2=0; %velocity
a2=0; %acceleration
x_2=[q2;
v2;
a2]; %initial conditions
%initial conditions of the platoon
x=[x_0; x_1; x_2];
[t,y3]=ode45(@code,t,x);
%% concating
time=linspace(0,20,300);
%parameters of 1st
q_1=[y1(:,1);y2(:,1);y3(:,1)];
%parameters of 2nd
q_2=[y1(:,4);y2(:,4);y3(:,4)];
%parameters of 3rd
q_3=[y1(:,7);y2(:,7);y3(:,7)];
plot(time',q_1,time',q_2,time',q_3)
The system response is not as expected from ode45. I found out that the reason it does not match is due to the vehicles depending upon the predecessor's acceleration which does not happen as I shift to ode 45 mid code. I tried giving initial condition as some acceleration but it just messed up the rectangular pulse input that I am giving. Is there any other way to feed the ode45 solver a rectangular pulse?
採用された回答
その他の回答 (1 件)
time=linspace(0,20,300);
is wrong.
You must concatenate the t-vectors returned from ode45 in the three calls in the same way as you did it to define q_1, q_2 and q_3.
We cannot test your code since you didn't include "code.m".
1 件のコメント
Kashish Pilyal
2022 年 8 月 15 日
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

