ODE45 in feedback loop

Hello!
I'm trying to plot a sum of differential equation system solutions using ODE45. Problem is my code doesnt wanna run more than 41 times.
% SLAVE SYSTEM
S=1;
xs = [];
for i=1:1:42
f_s = @(t,x_s) [x_s(2)+k1*S;
x_s(3)+k2*S;
a1*x_s(1)+a2*x_s(2)+a3*x_s(3)+10^(-4)*(exp(x_s(1)/0.026)-1)+k3*S];
[t,xs] = ode45(f_s,[0 0.001],[0.1 0.1 0.1]);
x_slave_summa = xs(:,1)+xs(:,2)+xs(:,3);
figure(4)
plot(t,x_slave_summa)
S = c1*(xs(i,1)-xg(i,1))+c2*(xs(i,2)-xg(i,2))+c3*(xs(i,3)-xg(i,3));
i=i+1;
end
1.PNG
Idea is basically that I wanna solve equation system where f(y1,y2,y2) is as written in my code and I calculate S from previous diff eq solutions last sample (S=1 -> solve diff eq system -> calculate new S -> S=new_S ->solve diff eq system ......). If I increment for loops end value I get:
Index in position 1 exceeds array bounds (must not exceed 41).
Error in test (line 76)
S =
c1*(xs(i,1)-xg(i,1))+c2*(xs(i,2)-xg(i,2))+c3*(xs(i,3)-xg(i,3));
What is causing this problem and how can I get my loop to run longer?
Thanks!

Risposte (0)

Categorie

Scopri di più su Programming in Centro assistenza e File Exchange

Prodotti

Release

R2018b

Richiesto:

il 15 Dic 2019

Community Treasure Hunt

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

Start Hunting!

Translated by