I have learned two coupled matrix ODEs for the linear quadratic tracking problem in optimal control, which are below:
where
I am trying to write a MATLAB that solves the differential equations simultaneously. Here is what I have so far:
function [dSdt dGdt] = mRiccati2(t, S, A, B, Q, R, G, r, h)
k = 1+floor(t/h);
S = reshape(S, size(A)); %Convert from "n^2"-by-1 to "n"-by-"n"
dSdt = A'*S + S*A - S*B*inv(R)*B'*S + Q; %Determine derivative
dGdt = -(A'- S*B*inv(R)*B')*G + Q*r(:,k);
dSdt = dSdt(:); %Convert from "n"-by-"n" to "n^2"-by-1
end
And I try to call the function as
[T S G] = ode45(@(t, S, G)mRiccati2(t, S, A, B, Q, R, G, r, h), [0:h:Tfinal], S0, G0);
Unfortunately, I am getting this error:
Not enough input arguments.
Error in HW5 (line 24)
[T S G] = ode45(@(t, S, G)mRiccati2(t, S, A, B, Q, R, G, r, h), [0:h:Tfinal], S0, G0);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in HW5 (line 24)
[T S G] = ode45(@(t, S, G)mRiccati2(t, S, A, B, Q, R, G, r, h), [0:h:Tfinal], S0, G0);
Is there a general way to properly solve a coupled matrix ODE with ode45
?