"Inputs must be floats, namely single or double" when running ode45 for LQ tracker
2 views (last 30 days)
Show older comments
Using matlab 2017b on windows 10 64-bit I am trying to run ode45 to solve the matrix ricatti equation for a discrete time LQ tracker with fixed final time T. When I run the ode45 I get the error "Inputs must be floats, namely single or double.". Any support on getting a result from ode45 would be incredible.
clc
clear
close all
A=[0 1 0 0;0 -1 -3.22 0.5;0 0 0 1;0 0 17.71 -2.75]; %state matrix
B=[0 0;1 -0.5;0 0;-0.5 2.75]; %input matrix
C=[1 0 0 0;0 0 1 0;0 0 1 0;0 0 0 1]; %output matrix
[An,Am]=size(A);
[Bn,Bm]=size(B);
[Cn,Cm]=size(C);
t0=0;
T=20; %final time (sec)
tspan=[-T,t0]; %for reverse integration of S_dot
%weighing of cost function
W=[1 0 0 0;0 1 0 0;0 0 1 0; 0 0 0 1];
Q=[1 0 0 0;0 1 0 0;0 0 1 0; 0 0 0 1];
R=[1 0; 0 1];
%generate symmetric symbolic matrix S(t)
S_t=sym('S_t',[An,Am]);
S_t=tril(S_t,0)+tril(S_t,-1).';
S_dot=-(S_t*A+A'*S_t-S_t*B*(inv(R))*B'*S_t+C'*Q*C); %differential matrix ricatti equation
S_dot = S_dot(:); %Convert from "n"-by-"n" to "n^2"-by-1 (matrix turned into transpose vector for ode45)
S_T=C'*W*C; %boundary condition @ final time T
S_T=S_T(:); %boundary condition as transpose vector
[time, state]=ode45(@(t,S_t) S_dot,tspan,S_T)
2 Comments
Answers (1)
Walter Roberson
on 22 Oct 2018
Replace
[time, state]=ode45(@(t,S_t) S_dot,tspan,S_T)
with
syms t;
F = matlabFunction(S_dot, 'vars', {S_t(:)});
[time, state] =ode45(F, tspan, S_T)
0 Comments
See Also
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!