"Inputs must be floats, namely single or double."

4 views (last 30 days)
Hi,
I writing a matlab mfile code to generate an optimal control for my system so that the system state variables will follow a tracking reference r(t)= t^2,
Since this is a linear quadratic tracking problem, I need to use ode45 to generate the control u at each time step with respect to time
This is my main script:
%% System Parameters
%
global a b p q R T ST VT x0 % global all parameters
a = 1; % system A matrix
b = 1; % system B matrix
p = 10; % final time weight value
q = 5; % tracking weight value
R = 2; % control effort
T = 20; % final time (seconds)
x0 = 3; % initial condition x(t0)=3
%
%% System Model and Boundry Conditions
% since the system is scalar, we use scalar functions for table 4.1-1
%
ST = p; % S(T)=p
T = 20; % final time (secs)
tspan = 0:1:T; % define time span
syms t; % define t as a variable
r(t) = t^2; % define tracking function
VT = p*r(T); %V(T) = p*r(T)
sysc = ss(a, b ,0, 0); % generate the system
% plot (r(tspan)) %generate r(t) plot
% hold on
% grid on
%
%% Simulation (backwards in time)
%
[tor yb] = ode45(@q1fcn1,[0 T],[ST, VT]);
This is my ode function script:
function dyb = q1fcn1(tor, yb)
dyb = zeros(2,1);
global a b p q R T ST VT x0 % global all parameters
a = 1; % system A matrix
b = 1; % system B matrix
p = 10; % final time weight value
q = 5; % tracking weight value
R = 2; % control effort
ST = p; % S(T)=p
T = 20; % final time (secs)
tspan = 0:1:T; % define time span
syms t; % define t as a variable
r(t) = t^2; % define tracking function
VT = p*r(T); %V(T) = p*r(T)
S = yb(1);
V = yb(2);
dS = -(2*a*S-((b^2)*(S^2))/R+q);
dV = -(((a-(b^2)*S)/R)*V+q*r(tspan));
dyb(1)=S;
dyb(2)=V;
end
I know something is off, but after some searching online, I still have no idea which part in my ode fuction got wrong.
Thank you very much in advance for any help I get.

Accepted Answer

Walter Roberson
Walter Roberson on 12 Nov 2019
syms t; % define t as a variable
r(t) = t^2; % define tracking function
VT = p*r(T); %V(T) = p*r(T)
t is symbolic so r is symbolic so VT is symbolic. You cannot use a symbolic parameter for initial conditions.
ode45 is completely unable to process symbolic formula. Use dsolve for symbolic systems
  1 Comment
Kent Deng
Kent Deng on 12 Nov 2019
Thank you very much,
for now the error msg is gone
although the ode45 still couldn't return a solution but at least the error msg is gone.
Thanks again

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!