potting the integral of a state

2 views (last 30 days)
Basetsana Sebolao
Basetsana Sebolao on 19 May 2021
Edited: Paul on 20 May 2021
Hi everyone
I would like to enquire about integralting a state.Afer solving a state space equation on matlab sing ode45, how does one go about plotting the integral of a state, please kindly assist, thank you in advance!

Answers (1)

Torsten
Torsten on 19 May 2021
If y'(t)=f(t,y) is the state space equation, you get the integral of y by simultaneously solving z'(t)=y(t), z(0)=0.
  2 Comments
Basetsana Sebolao
Basetsana Sebolao on 19 May 2021
I see, I think I posed my question incorrectly. my apologies, My states (di) are respresented in a matrix, I have attached my code: By runnning the code below in the command window I am able to plot y(1), y(2), y(3), y(4) ( I have four states)
tspan = [0 0.005];
iniCon = [0; 0; 0; 0];
[t,y] = ode45(@sys, tspan, iniCon);
figure
cols = size(y,2);
for k = 1:cols
subplot(cols,1,k)
plot(t, y(:,k))
grid
xlim([0 1.5E-4])
title(sprintf('y_{%d}',k))
After plotting y(1), y(2), y(3), I am trying to plot the integrals of y(1), y(2) ...however, I am having a hard time plotting the integrals.
Paul
Paul on 19 May 2021
Edited: Paul on 20 May 2021
Implement what @Torsten suggested.
Change the last line of sys to:
di = [Ai + Bv; i];
Change iniCon to:
iniCon = [0;0;0;0;zeros(4,1)]; % assuming you want the integrals of y(i) to start from zero
Then y will have 8 states, the first 4 are i and the second 4 are the integrals of i

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!