ode23: using different sets of ODE equations at certain time intervals t

7 views (last 30 days)
I have an equation modeling a synchronous power generator connected to the grid. A set of non-linearl differential equations models the synchronous generator's operating conditions (load angle and rate of change for load angle, or the "swing equation").
I need to model what the synchronous generator is doing after a fault occurs in the power grid. Therefore, the coefficients of the non-linear ODE's will change when the fault event occurs at time "t". How do I tell ode23 to stop using the initial ODEs and begin using the new post-fault ODEs?
I am having difficulty with indices exceeding array bounds. My guess is that my matrices aren't lining up. I definitely do not know how ode23 indexes matrices and how to write IF and FOR statements for each element of the time matrix.
The fault occurs at t = 2 seconds and lasts until 2.066 seconds.
How can I tell ode23 to use a different set of ODEs based on the value of elements in the time matrix?
Here is my code so far. I might be heading in a completely wrong direction:
%SYNC_GEN_ODE_SOLVER.m
%Initial condition matrix
y0 = [0.368 ; 0];
%Time Index Matrix
tIndex = linspace(0,5,1000);
%solution calls MATLAB's build-in ode23 solver
[t,y] = ode23(@ODE_EQUATIONS, tIndex, y0);
plot(t, y(:,1), '-', t, y(:,2), '--')
title('Dampened solution at steady state:');
xlabel('time t');
ylabel('solution y');
legend('Load Angle', 'Speed Response');
%Function below shows ODE-equations
function dy = ODE_EQUATIONS(tIndex, y)
% D = Damping Coefficient
for i = 1:1000
%pre-fault ODEs
if tIndex(i) < 2.000
A = 30.16; B = 83.77; D = 0.052; U = 0;
dy = [y(2); A - B*sin(y(1))- D*y(2) + U];
%fault ODEs
elseif (tIndex(i) >= 2.000) && (tIndex(i) <= 2.066)
A = 30.16; B = 41.885; D = 0.0; U = 0;
dy = [y(2); A - B*sin(y(1))- D*y(2) + U];
%post-fault ODEs
elseif tIndex(i) >= 2.066
A = 30.16; B = 41.885; D = 0.052; U = 0;
dy = [y(2); A - B*sin(y(1))- D*y(2) + U];
end
end
end
Any idea on how to get the IF statements and FOR loop to select the different ODE sets would be appreciated.
My errors from MATLAB returned:
Index exceeds array bounds.
Error in ODE_SOLVER_3_Parts456_not_working>ODE_EQUATIONS (line 27) if tIndex(i) < 2.000
Error in odearguments (line 90) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode23 (line 114) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in ODE_SOLVER_3_Parts456_not_working (line 9) [t,y] = ode23(@ODE_EQUATIONS, tIndex, y0);
Thank you

Answers (1)

Torsten
Torsten on 12 Nov 2018
Take a look at the answer given here:
https://de.mathworks.com/matlabcentral/answers/429332-using-ode45-to-solve-quarter-model-of-suspension-with-input-function-an-endless-obstacle
Best wishes
Torsten.

Community Treasure Hunt

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

Start Hunting!